Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# XSD无法基于继承的类从XML创建类_C#_.net_Xml_Xml Serialization_Xsd.exe - Fatal编程技术网

C# XSD无法基于继承的类从XML创建类

C# XSD无法基于继承的类从XML创建类,c#,.net,xml,xml-serialization,xsd.exe,C#,.net,Xml,Xml Serialization,Xsd.exe,我在基于序列化另一个C#类生成的XML创建*.cs(C#类)时遇到问题。XSD.exe引发以下错误: - A column named 'Conditions' already belongs to this DataTable: cannot set a nested table name to the same name. 我的流程如下所示: public class A { public A(){} private List<string> _cond = n

我在基于序列化另一个C#类生成的XML创建*.cs(C#类)时遇到问题。XSD.exe引发以下错误:

- A column named 'Conditions' already belongs to this DataTable: cannot set a
  nested table name to the same name.
我的流程如下所示:

public class A
{
   public A(){}
   private List<string> _cond = new List<String>();
   public List<string> Conditions 
   {
      get{ return _cond; }
      set{ _cond = value }
   }
}

public class B:A
{
}
public class C:A
{
}

public class Data
{
  B b = new B();
  C c = new C();
  /* ... ADD SOME DATA etc ... */
} 

// After that I serialize to XML the "Data" class object
  • 编写一些C#代码(下面的示例)
  • 序列化为XML使用XSD.EXE
  • 创建*.cs反序列化为新的*.cs
  • (用于运输)等
  • 序列化为XML的类(在第1点中)如下所示:

    public class A
    {
       public A(){}
       private List<string> _cond = new List<String>();
       public List<string> Conditions 
       {
          get{ return _cond; }
          set{ _cond = value }
       }
    }
    
    public class B:A
    {
    }
    public class C:A
    {
    }
    
    public class Data
    {
      B b = new B();
      C c = new C();
      /* ... ADD SOME DATA etc ... */
    } 
    
    // After that I serialize to XML the "Data" class object
    
    公共A类
    {
    公共A(){}
    私有列表_cond=新列表();
    公开列表条件
    {
    获取{return\u cond;}
    设置{u cond=value}
    }
    }
    B级:A级
    {
    }
    公共C类:A
    {
    }
    公共类数据
    {
    B=新的B();
    C=新的C();
    /*…添加一些数据等*/
    } 
    //之后,我将“数据”类对象序列化为XML
    

    有人能提出解决办法吗?!这显然是由inherided condition属性引起的,您可以更改xsd.exe创建输出的方式,在您的情况下,使用/c(lasses)开关是有意义的。然后,它将不创建数据集,而是创建“普通”类


    还有一个,它有一个相当不错的代码生成器。

    “无用的论坛…–condproblem”我们应该如何利用这个评论?这就解释了为什么在我之前没有人回答。