【发布时间】:2014-04-04 11:08:00
【问题描述】:
InterfaceType interfaceType = new InterfaceType() { definitions = new UnitType[0][] };
try
{
interfaceType = fileManager.deserialize<InterfaceType>("C:\\Users\\Yogev\\Desktop\\namer_NMC_TILTAN_Interface.xml");
}
catch (Exception ex)
{
Debug.WriteLine("Error deserialize" + ex.ToString());
}
这是类的创建和反序列化方法的调用。
我正在反序列化来自 xsd.exe 的自动生成(部分)类。这是课程:
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://tempuri.org/IRSSchema.xsd")]
[System.Xml.Serialization.XmlRootAttribute("interface", Namespace="http://tempuri.org/IRSSchema.xsd", IsNullable=false)]
public partial class InterfaceType {
private System.Xml.XmlNode[] descriptionField;
private UnitType[][] definitionsField;
private IncludeType[] includeField;
private GroupType[] groupField;
private string nameField;
private string formatField;
private bool isBigEndianField;
private bool isBigEndianFieldSpecified;
我遇到了一个异常:
error CS0030: Cannot convert type 'UnitType[]' to 'UnitType'
error CS0029: Cannot implicitly convert type 'UnitType' to 'UnitType[]'
【问题讨论】:
-
向我们展示 XML 文件。尤其是带有“定义”元素的部分。
-
你的意思是我想要反序列化的 xml 文件吗?
标签: c# xml serialization xsd