C# 用于序列化和反序列化的XmlRootAttribute类

C# 用于序列化和反序列化的XmlRootAttribute类,c#,xml,serialization,deserialization,C#,Xml,Serialization,Deserialization,我想创建一个用于序列化和反序列化的类。序列化时,属性名称应为MyNameRequestType,反序列化时,属性名称应为MyNameResponseType 问题是我应该如何创建或覆盖XmlRootAttribute 例如 您必须使用该属性。如果希望生成的XML元素的名称与类名不同,则必须指定ElementName [System.SerializableAttribute()] [System.Xml.Serialization.XmlRootAttribute("MyNameRequestT

我想创建一个用于序列化和反序列化的类。序列化时,属性名称应为MyNameRequestType,反序列化时,属性名称应为MyNameResponseType

问题是我应该如何创建或覆盖XmlRootAttribute

例如

您必须使用该属性。如果希望生成的XML元素的名称与类名不同,则必须指定ElementName

[System.SerializableAttribute()]
[System.Xml.Serialization.XmlRootAttribute("MyNameRequestType", IsNullable = false)]
public class MyClass
{
    public string MyProperty { get; set; }
}