XSD Gen Classes That Reference a Common Type

ⅰ亾dé卋堺 提交于 2019-12-03 02:52:08

You can use XSD.exe with multiple file arguments:

xsd .\XSD\Common.xsd .\XSD\Employee.xsd .\XSD\Company.xsd /c /o:. /n:"DomainModel"

You basically want to split out the common types into a common assembly which is references by your other types. You have two options:

  1. Manually split them out. I know this is a generated file but if your source schemas are fairly static then it's a one off exercise.
  2. Use svcutil.exe instead. However this is much more complicated and actually you may not even be able to do this unless your schemas all abide by certain guidelines. If you are interested see below for the process.

If you fancy option 2 above then here is the general process:

  1. Extract the types from Common.xsd using the /dconly flag on svcutil. This will generate a class file with your common types.
  2. Compile this class into an assembly
  3. Extract the types from A.xsd using the /r flag and referencing your CommonTypes.dll assembly.
  4. Do the same for B.xsd

However, this approach is based on svcutil using the DataContractSerializer to do the work, as the /r flag is not available to XmlSerializer. And this will only work if the your schemas adhere to the rather strict DCS rules (can be found here: http://msdn.microsoft.com/en-us/library/ms733112.aspx).

If these rules are not adhered to then svcutil will fall back to using XmlSerializer which does not support /r flag.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!