編集2
そのため、現在 CF チームに確認していますが、バグが見つかったと思います。これはそれをさらによく示しています:
public class MyAttribute : Attribute
{
public MyAttribute(UnmanagedType foo)
{
}
public int Bar { get; set; }
}
[StructLayout(LayoutKind.Sequential)]
public struct Test
{
[CLSCompliant(false)]
[MyAttribute(UnmanagedType.ByValArray, Bar = 4)]
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
public ushort[] ArrayShorts;
}
class Program
{
static void Main(string[] args)
{
FieldInfo field_info = typeof(Test).GetField("ArrayShorts");
object[] custom_attributes = field_info.GetCustomAttributes(typeof(MarshalAsAttribute), false);
Debug.WriteLine("Attributes: " + custom_attributes.Length.ToString());
custom_attributes = field_info.GetCustomAttributes(typeof(MyAttribute), false);
Debug.WriteLine("Attributes: " + custom_attributes.Length.ToString());
custom_attributes = field_info.GetCustomAttributes(typeof(CLSCompliantAttribute), false);
Debug.WriteLine("Attributes: " + custom_attributes.Length.ToString());
}
}
完全なフレームワークの下で、私はこれを返します:
Attributes: 1
Attributes: 1
Attributes: 1
CF 3.5 では、次のようになります。
Attributes: 0
Attributes: 1
Attributes: 1
したがって、MarshalAsAttribute ではなく、カスタムまたは BCL 内の属性を完全に返すことができることがわかります。
編集 3
よし、もう少し掘り下げてみたところ、仕様に従えば、CF の動作は実際には正しいことがわかりました。それはすべての論理に反しますが、正しいです。