在XML序列化所需的属性所需、属性、序列化、XML

2023-09-04 12:18:08 作者:彼此守候

例如我有一流的序列化

[Serializable]
class Person
{
    [XmlAttribute("name")]
    string Name {get;set;}
}

我需要必需的name属性。如何做到这一点的。NET?

I need to make Name attribute required. How to do this in .NET?

推荐答案

首先, [Serializable接口] 不使用XML序列化。

First of all, [Serializable] is not used by the XML Serializer.

其次,就没有办法使它所需

Second, there is no way to make it required.