C# 使用XSD.exe生成的这些类级属性中,哪些可以安全地丢弃?

C# 使用XSD.exe生成的这些类级属性中,哪些可以安全地丢弃?,c#,custom-attributes,xml-deserialization,xsd.exe,C#,Custom Attributes,Xml Deserialization,Xsd.exe,我对XML模式文件(.XSD)使用XSD.exe来生成C类,用于反序列化符合所述XML模式的XML数据文件 我注意到所有生成的类都添加了以下类级属性 [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.17929")] [System.SerializableAttribute()] [System.Diagnostics.DebuggerStepThroughAttribute()] [System.Compone

我对XML模式文件(
.XSD
)使用XSD.exe来生成C类,用于反序列化符合所述XML模式的XML数据文件

我注意到所有生成的类都添加了以下类级属性

[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.17929")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
在某些情况下,该工具还生成了
xmlementattribute
属性,我很清楚这是正确反序列化所必需的

[System.Xml.Serialization.XmlElementAttribute("Field")]
所以除了这个
xmlementattribute
,前面提到的哪些属性是反序列化成功所必需的呢。我知道我可以一个接一个地删除它们并进行尝试,但是有很多类,我希望尽可能保持我的类定义“干净”,而不必到处都有不必要的属性

下面是一个由XSD.exe生成的示例类定义,以防您还需要查看该类

[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.17929")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
public partial class CrystalReportReportFooter {

    private CrystalReportReportFooterSection sectionField;

    /// <remarks/>
    public CrystalReportReportFooterSection Section {
        get {
            return this.sectionField;
        }
        set {
            this.sectionField = value;
        }
    }
}
[System.CodeDom.Compiler.GeneratedCodeAttribute(“xsd”、“4.0.30319.17929”)]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute(“代码”)]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
公共部分类CrystalReportFooter{
私有CrystalReportFooterSection字段;
/// 
公共CrystalReportFooter部分{
得到{
返回此.section字段;
}
设置{
this.sectionField=值;
}
}
}

谢谢,

应该可以安全删除,除非重新生成代码的工具需要这样做

[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.17929")]

您需要这样做,因为这是告诉类它可以序列化的原因

[System.SerializableAttribute()]

这是可以删除的。这纯粹是为了调试,如果添加自定义代码,可能会妨碍以后的调试

[System.Diagnostics.DebuggerStepThroughAttribute()]

这是可以删除的。仅用于IDE或任何利用它的WYSIWYG设计器

[System.ComponentModel.DesignerCategoryAttribute("code")]

这取决于你。基本上,它告诉序列化程序该类是匿名XSD类型

[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]

杰出的谢谢@TyCobb!