我已经使用2.0框架尝试了以下代码,我得到了一个属性,但是当我在紧凑框架上尝试这个时,它总是返回一个空数组.MSDN文档说它支持,我做错了吗?
Test x = new Test();
FieldInfo field_info = x.GetType().GetField("ArrayShorts");
object[] custom_attributes = field_info.GetCustomAttributes(typeof(MarshalAsAttribute), false);
[StructLayout(LayoutKind.Sequential)]
public struct Test
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
public ushort[] ArrayShorts;
}
Run Code Online (Sandbox Code Playgroud) c# attributes compact-framework marshalling getcustomattributes