Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

An example of MemberTypes.Custom and MemberTypes.TypeInfo member

There are eight different enumerated values for System.Reflection.MemberTypes. Five map directly to specific MemberInfo classes (ConstructorInfo, MemberInfo, etc.). The MemberTypes.NestedType can be thought of as Type rather than a MemberInfo. I'm trying to get my head around (1) MemberTypes.Custom and (2) MemberTypes.TypeInfo members. Does anyone have an example of such members?

like image 471
bricklayer137 Avatar asked Aug 05 '13 22:08

bricklayer137


1 Answers

public class Foo
{
   public class Bar { }
}

With these two classes the following will be true.

typeof(Foo).MemberType == MemberTypes.TypeInfo
typeof(Foo.Bar).MemberType == MemberTypes.NestedType

Both TypeInfo and NestedType indicate that you are dealing with a type with the distinction whether the type is nested or not. The enumeration value TypeInfo just sticks with the naming convention while the actual subtype of MemberInfo is Type. On the one hand Type should have been called TypeInfo to stick with the naming convention, on the other hand it seems a bit questionable that Type is derived from MemberInfo in the first place. But that is just the way it is. Maybe member in MemberInfo should be better understood as assembly or type member instead of just type member.

Since .NET 4.5 there is new subclass TypeInfo inheriting from Type and accessible using the Type.GetTypeInfo() extension method; see there for the distinction.

I am not sure about MemberTypes.Custom but looking at CLI specification, especially II.10.2, it may be the case that this refers to custom attributes or other custom data associated with a type. Looking at the .NET reference source code does not provide additional insight either.

like image 130
Daniel Brückner Avatar answered Sep 28 '22 06:09

Daniel Brückner