を使用しますCustomAttributeBuilder
。例えば:
var cab = new CustomAttributeBuilder(
ctor, ctorArgs,
props, propValues,
fields, fieldValues
);
prop.SetCustomAttribute(cab);
(または関連するオーバーロードの 1 つ)
あなたの場合、それは次のようになります(これは純粋な推測です):
var attribType = typeof(DisplayAttribute);
var cab = new CustomAttributeBuilder(
attribType.GetConstructor(Type.EmptyTypes), // constructor selection
new object[0], // constructor arguments - none
new[] { // properties to assign to
attribType.GetProperty("Order"),
attribType.GetProperty("ResourceType"),
attribType.GetProperty("Name"),
},
new object[] { // values for property assignment
28,
typeof(CommonResources),
"DisplayComment"
});
prop.SetCustomAttribute(cab);
Order
、ResourceType
、Name
がプロパティであると仮定していることに注意してください。それらがfieldsの場合、別のオーバーロードがあります。