开发者

XSD cant create class from XML based on inherited classes

开发者 https://www.devze.com 2023-02-21 01:08 出处:网络
I got problem with creating *.cs (C# Class) based on XML generated by serializing another C# class. XSD.exe throws following error:

I got problem with creating *.cs (C# Class) based on XML generated by serializing another C# class. XSD.exe throws following error:

- A column named 'Conditions' already belongs to this DataTable: cannot set a
  nested table name to the same name.

My process looks like this:

  1. Writing some C# code (example below)
  2. Serialize to XML use XSD.EXE to
  3. create *.cs Deserialize to new *.cs
  4. (for shipping) etc

The classes which are serialized to XML (in point 1) looks like this:

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

Can anyone suggest of workaround ?! This is clearly cause by inherided condition property


You can change the way xsd.exe creates the output, n your case, it would make sense to use the /c(lasses) switch. Then, it will not create a dataset but "ordinary" classes instead.

There's also LinqToXsd, which has a fairly decent code generator.

0

精彩评论

暂无评论...
验证码 换一张
取 消