Access to attributes of ITypeReference

Apr 28, 2007 at 2:28 AM
I was wondering how can I use the code model interface to read the size of a ITypeReference?
In the Reflector, the "Code Model Viewer" shows the size under .Attributes/StructLayoutAttributee/Size

How can I access it through program?

thank you,
Apr 29, 2007 at 3:06 AM
Edited Apr 29, 2007 at 3:10 AM
Try this:

ITypeReference typeReference = ...;
ITypeDeclaration typeDeclaration = typeReference.Resolve();
if (typeDeclaration != null)
  foreach (ICustomAttribute attribute in typeDeclaration.Attributes)
    ITypeReference type =
      attribute.Constructor.DeclaringType as ITypeReference;
    if ((type != null) && ((type.Name == "StructLayoutAttribute"))
      // ...
Apr 29, 2007 at 10:36 AM
Thanks for the hint. I tried the code, but when I call the .Resolve() function, it seems the code goes in an infinite loop and never exits. Any idea what might be the problem?

Thank you,