我有一个简单的类我序列化。
I have a simple class I'm serializing.
[DataContract(Name = "Test", Namespace = "")]
public class Test
{
[DataMember(Order = 0, Name = "Text")]
public string Text { get; set; }
public Test() {}
}
这踢了以下XML:
<Test>
<Text>Text here</Text>
</Test>
我要的是:
<Test>
<Text type="MyType">Text here</Text>
</Test>
我如何添加属性的XML元素?
How do I add attributes the the XML elements?
在此先感谢。
您不能将属性添加到DataContract。你要么必须使用一个实现ISerializable的类或使用.NET XmlSerializer的。
You can't add attributes to a DataContract. You either have to use a class that Implements ISerializable or use the .Net XmlSerializer.