使用XSD从程序集中的类型生成XSD。exe,具有属性上的dataannotation属性

时间:2022-12-28 17:18:20

I was hoping to reuse some viewmodel classes with dataannotations to generate xsd files for the purpose of validating (and documenting) xml files from 3rd party systems. Xsd.exe generates the .xsd files fine, but dataannotation attributes like [Required] are not reflected in the xsd with f.ex. minOccurs=1.

我希望重用一些带有dataannotation的viewmodel类来生成xsd文件,以便从第三方系统验证(并记录)xml文件。Xsd。exe可以很好地生成.xsd文件,但是像[Required]这样的dataannotation属性并不反映在使用f.ex的xsd中。minOccurs = 1。

What options (if any) do I have here? The "easiest" would probably be to create my own xsd generation using reflection. Or could I get away with just creating the extra validation attributes in a separate xsd and use both when validating xml files towards it?

这里有什么选项(如果有的话)?“最简单”的方法可能是使用反射创建我自己的xsd生成。或者,我可以在单独的xsd中创建额外的验证属性,并在验证xml文件时使用它们吗?

Any other ideas?

任何其他想法?

1 个解决方案

#1


1  

I don't know of any other solution.

我不知道还有其他的解决办法。

I did write an XSD generator using reflection (to be able to include comments in my case) - it is quite a lot of work but definitely feasible.

我确实使用反射编写了XSD生成器(以便在我的例子中包含注释)——这是相当多的工作,但绝对是可行的。

#1


1  

I don't know of any other solution.

我不知道还有其他的解决办法。

I did write an XSD generator using reflection (to be able to include comments in my case) - it is quite a lot of work but definitely feasible.

我确实使用反射编写了XSD生成器(以便在我的例子中包含注释)——这是相当多的工作,但绝对是可行的。