Ho una classe semplice che sto serializzando.Come aggiungere un attributo XML utilizzando DataContract
[DataContract(Name = "Test", Namespace = "")]
public class Test
{
[DataMember(Order = 0, Name = "Text")]
public string Text { get; set; }
public Test() {}
}
Questa calcia fuori il seguente codice XML:
<Test>
<Text>Text here</Text>
</Test>
Quello che voglio è:
<Test>
<Text type="MyType">Text here</Text>
</Test>
Come posso aggiungere attributi gli elementi XML?
Grazie in anticipo.
'IXmlSerializable' per xml. –
A seconda del sistema che esegue la serializzazione, è possibile fare ciò che l'OP sta chiedendo: consultare: http://stackoverflow.com/questions/4858798/datacontract-xml-serialization-and-xml-attributes/4859084#4859084 – jeffreypriebe