【发布时间】:2018-11-22 19:57:10
【问题描述】:
我正在使用 .NET Framework 4.7 开发 C# 库。
我想将ProductionOrderXmlFile类转换成XML文件:
[Serializable]
public class Level
{
[XmlElement("Id")]
public byte Id { get; set; }
[XmlElement("Name")]
public string Name { get; set; }
[XmlElement("CodeType")]
public byte CodeType { get; set; }
[XmlElement("CodeSourceType")]
public byte CodeSourceType { get; set; }
[XmlElement("HelperCodeType")]
public byte HelperCodeType { get; set; }
[XmlElement("HelperCodeSourceType")]
public byte HelperCodeSourceType { get; set; }
[XmlElement("PkgRatio")]
public int PkgRatio { get; set; }
}
[Serializable]
public class VarData
{
[XmlElement("VariableDataId")]
public string VariableDataId { get; set; }
[XmlElement("LevelId")]
public byte LevelId { get; set; }
[XmlElement("Value")]
public string Value { get; set; }
}
/// <summary>
/// Class to load a production order from a xml file.
/// </summary>
[Serializable, XmlRoot("root")]
public class ProductionOrderXmlFile
{
[XmlElement("ProductionOrderName")]
public string ProductionOrderName { get; set; }
[XmlElement("NumItems")]
public int NumItems { get; set; }
[XmlElement("ProductCode")]
public string ProductCode { get; set; }
[XmlElement("Reduction")]
public float Reduction { get; set; }
[XmlArray("Levels")]
[XmlArrayItem("Level")]
public List<Level> Levels { get; set; }
[XmlArray("VariableDatas")]
[XmlArrayItem("VariableData")]
public List<VarData> VariableData { get; set; }
}
但在 public List<Level> Levels { get; set; } 和 public List<VarData> VariableData { get; set; } 字段中我收到警告:
警告 CA2235 字段级别是 ProductionOrderXmlFile 类型的成员,该类型可序列化,但属于不可序列化的 System.Collections.Generic.List 类型
还有:
警告 CA2235 字段变量数据是 ProductionOrderXmlFile 类型的成员,该类型可序列化,但属于不可序列化的 System.Collections.Generic.List 类型
我需要做些什么来避免这些警告?
【问题讨论】:
标签: c# xml serializable