SortedLists.
example, my type (tmptarget) has a SortedList member called tmptarget.List.
"Jon Shemitz" <jon@midnightbeach.com> wrote in message
news:4485089E.EF5B406C@midnightbeach.com...
> AdamM wrote:
>
>> How do you take a PropertyInfo and get an instance of the object
>> described
>> by it? For example, I want to get the actual instance of the object
>> described by "pi" in the snippet below (not the object's value like what
>> GetValue() provides, but a reference to the object itself):
>
>> MemberInfo[] arrayMemberInfo;
>> Type t = tmptarget.GetType();
>> arrayMemberInfo = t.FindMembers(MemberTypes.Property,
>> BindingFlags.Public | BindingFlags.NonPublic |
>> BindingFlags.Instance | BindingFlags.SetProperty,
>> new MemberFilter(DelegateToSearchCriteria), "ReferenceEquals");
>> PropertyInfo pi = t.GetProperty(arrayMemberInfo[0].Name);
>
> You mean how do you go from a value like "pi" to a value like "t"? You
> don't.
>
> A Type value is a runtime description of a class. It's the runtime
> equivalent of a compiletime class, and a Type value is as distinct
> from an instance of the class as the compiletime class is distinct
> from an instance of the class.
>
> A PropertyInfo value is a runtime description of a property, which is
> a class member. To call GetValue, you need to supply an instance
> reference, like your "tmptarget".
>
> You can go from a PropertyInfo to its ReflectedType, which is the Type
> of the class which contains the property. You can go from a
> PropertyInfo to its DeclaringType, which is the Type of the class
> which contains the property. (If the ReflectedType is not the same as
> the DeclaringType, the ReflectedType inherited the member from the
> DeclaringType.)
>
> But you can't go from a PropertyInfo to an instance any more than you
> can go from a Type to an instance or from a compiletime class to an
> instance. All the pointers are one way, instance to type, not type to
> instances.
>
> --
>
> .NET 2.0 for Delphi Programmers <
http://www.midnightbeach.com/.net> >
> Delphi skills make .NET easy to learn
> Just printed, and shipping now.