Access to attributes of ITypeReference

Apr 28, 2007 at 3:28 AM
Hello,
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,
--mehrdad.
Coordinator
Apr 29, 2007 at 4:06 AM
Edited Apr 29, 2007 at 4: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 11:36 AM
Hello,
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,