0
我有一個代碼生成的類,它有一組屬性屬性。我想爲這些屬性添加額外的屬性,但是我不能在代碼生成的類上這樣做。因此,我利用MetadataTypeAttribute
來修飾輔助類中的其他屬性;MetadataTypeAttribute不向屬性裝飾附加屬性
// Code generated class - can't touch this
public partial class MyClass
{
public MyType MyProperty { get; set; }
}
// Partial class allowing extended attributes
[MetadataType(typeof(MyClass_AdditionalAttributes))]
public partial class MyClass
{
}
// Defines extra attributes to be appended to
// properties that match in the partial class
public class MyClass_AdditionalAttributes
{
// Do not serialise the MyProperty property
[XmlIgnore]
public MyType MyProperty;
}
但是,這是行不通的。使用.NET反射器,XmlIgnoreAttribute
未被裝飾到MyClass.MyProperty
屬性。任何人都可以看到我做錯了什麼?