MemberTypes.Custom and MemberTypes.TypeInfo example

System.Reflection.MemberTypes has eight different enumerated values. Five maps directly for specific MemberInfo classes (ConstructorInfo, MemberInfo, etc.). The type MemberTypes.NestedType can be considered a type, not a MemberInfo. I am trying to expand my head (1) MemberTypes.Custom and (2) MembersTypes.TypeInfo. Does anyone have an example of such members?

+6
source share
1 answer
public class Foo { public class Bar { } } 

The following will be done with these two classes.

 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 difference whether the type is nested or not. The value of the TypeInfo enumeration simply adheres to the naming convention, while the actual subtype of MemberInfo is Type . On the one hand, Type should be called TypeInfo to adhere to the naming convention, on the other hand, it seems a little dubious that Type comes from MemberInfo in the first place. But the way it is. Maybe a member in MemberInfo should be better understood as an assembly or type element, not just a type member.

Since .NET 4.5 there is a new subclass of TypeInfo that inherits from Type and is available using Type.GetTypeInfo() extension method ; see there is a difference.

I'm not sure about MemberTypes.Custom , but I look at the CLI specification , especially II.10.2, maybe this refers to user attributes or other user data associated with the type. Looking at . The .NET source code also provides no additional information.

+4
source

Source: https://habr.com/ru/post/951071/


All Articles