【发布时间】:2011-06-17 10:34:50
【问题描述】:
我有一个List<TransformationItem>.TransformationItem 只是多个类的基类,例如ExtractTextTransform 和InsertTextTransform
为了使用内置的 XML 序列化和反序列化,我必须使用 XmlArrayItemAttribute 的多个实例,如 http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlarrayitemattribute%28v=vs.80%29.aspx 中所述
您可以应用 XmlArrayItemAttribute 或 XmlElementAttribute 的多个实例来指定可以插入到数组中的对象类型。
这是我的代码:
[XmlArrayItem(Type = typeof(Transformations.EvaluateExpressionTransform))]
[XmlArrayItem(Type = typeof(Transformations.ExtractTextTransform))]
[XmlArrayItem(Type = typeof(Transformations.InsertTextTransform))]
[XmlArrayItem(Type = typeof(Transformations.MapTextTransform))]
[XmlArrayItem(Type = typeof(Transformations.ReplaceTextTransform))]
[XmlArrayItem(Type = typeof(Transformations.TextItem))]
[XmlArrayItem(ElementName = "Transformation")]
public List<Transformations.TransformationItem> transformations;
问题是,当我使用反射获取 GetCustomAttribute() 的 ElementName 属性时,我得到了 AmbiguousMatchException。
我该如何解决这个问题,比如获取ElementName?
【问题讨论】:
标签: c# reflection custom-attributes