Finding structs in the .net framework

  • Thread starter Thread starter Jimi
  • Start date Start date
J

Jimi

How would I go about finding all structs in a framework assembly?

Assembly asm = Assembly.LoadWithPartialName(sSystemAssembly);
foreach (System.Type asmType in asm.GetExportedTypes())
{
if (asmType.IsValueType && asmType.IsSealed && !
asmType.IsEnum)
...


This just gets messy - I know there's an "IsClass" property on the
System.Type object, I thought there would logically be a "IsStruct",
but no luck. Is there a reliable method of getting structs?
 
Hey Jimi,

I think the way you are doing it is the right way and I don't think there is another easier way. .net has no concept of structs. It only knows about reference types and value types. If you define a struct (named Test), the C# compiler will emit the following declaration:

..class public sequential ansi sealed beforefieldinit Test
extends [mscorlib]System.ValueType

So you have to test for the type being a sealed valuetype and not an enum.

Regards, Jakob.
 
Back
Top