<p>Using C#, does anyone know how to get the MarshalAsAttribute's Sizeconst value in runtime ?</p>

<p>Eg. I would like to retrieve the value of 10.</p>

<pre><code>[StructLayout[LayoutKind.Sequential, Pack=1]
Class StructureToMarshalFrom
{
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 10)]
    public byte[] _value1;
}
</code></pre>

Yup, with reflection:
```
```
FieldInfo field = typeof(StructureToMarshalFrom).GetField("_value1");
object[] attributes = field.GetCustomAttributes(typeof(MarshalAsAttribute), false);
MarshalAsAttribute marshal = (MarshalAsAttribute) attributes[0];
int sizeConst = marshal.SizeConst;
```
```
(Untested, and obviously lacking rather a lot of error checking, but should work.)