retrieving nonprimitive types in an assembly with .NET Reflection
Is there any class or specific method for getting non-primitive types in an assembly? FieldInfo.G开发者_运维技巧ettype() will do for primtive types but what about non-primitive types?
It's not at all clear what you mean - and "FieldInfo.GetType works for primitive types" is an odd starting point, as if you call GetType()
on a FieldInfo
reference, you'll always get a type derived from FieldInfo
... whereas if you use FieldInfo.FieldType
, that will access the type of the field.
But yes, you can definitely get at the types within an assembly, e.g. with Assembly.GetType(string)
to get one particular type, or Assembly.GetTypes()
to get all the types.
If you could tell us more about what you're trying to achieve and give us a code sample which shows what information you have and what you're trying to get, that would help us to help you more.
I'm not sure what actually is your question but guess you are looking for typeof(Type)
.
AssemblyInstance.GetTypes().Where(x => !x.IsPrimitive)
if you are looking for the NonPrimitive fields in a type:
TypeInstance.GetFields().Where(x => !x.FieldType.IsPrimitive)
精彩评论