Visual Studio XSD工具:生成集合而不是数组

时间:2021-07-12 17:17:24

I generated some C# classes from an XSD using the Visual Studio XSD utility and it generated arrays for storing a collection of elements, rather than one of the built-in generic Collection<T> (or related) classes.

我使用Visual Studio XSD实用程序从XSD生成了一些c#类,它生成了用于存储元素集合的数组,而不是一个内置的泛型集合 (或相关)类。

None of the command line parameters mentioned in xsd /? mention anything about generating collections rather than arrays, but I know that this can be done with web service proxy classes that Visual Studio generates, so I figured it must be possible.

xsd /?中提到的命令行参数没有一个?提到任何关于生成集合而不是数组的内容,但是我知道这可以通过Visual Studio生成的web服务代理类来实现,所以我认为这是可能的。

Does anybody know how to have the XSD utility generate collection classes rather than arrays?

有人知道如何让XSD工具生成集合类而不是数组吗?

4 个解决方案

#1


8  

Found this post when searching for an answer. I'm using this tool: http://xsd2code.codeplex.com/

在搜索答案时找到了这篇文章。我正在使用这个工具:http://xsd2code.codeplex.com/

#2


1  

The problem is that XSD is XML - language agnostic. It can't use anything from Java or C# that the other doesn't support. Arrays are the lowest common denominator.

问题是XSD与XML语言无关。它不能使用其他不支持的任何Java或c#。数组是最小公分母。

Java developers use OXM libraries like XStream to marshal objects to XML and back. It allows you to specify custom types when going from objects to XML. Sounds like you'll have to find something similar in the .NET toolbox.

Java开发人员使用诸如XStream之类的OXM库将对象编组到XML并返回。它允许您在从对象到XML时指定自定义类型。听起来你必须在。net工具箱中找到类似的东西。

This isn't an answer to your question, but it's the reason why I think XSD won't do the job. Like a Java developer reaching out to XStream, you'll have to look elsewhere.

这不是对您问题的回答,但这是我认为XSD不能胜任这个工作的原因。就像Java开发人员接触到XStream一样,您必须到别处寻找。

#3


1  

You've seen the ability to use collections with Service References, not with Web References. Look at the svcutil.exe utility instead. It looks like svcutil /t:code file.xsd might do this for you.

您已经看到了使用服务引用来使用集合的能力,而不是使用Web引用。看看svcutil。exe实用程序。它看起来像svcutil /t:代码文件。xsd可能为您实现这一点。

#4


1  

I am not aware of any tools out there at this time that do this reliably, unfortunately.

不幸的是,目前我还不知道有什么工具可以可靠地做到这一点。

There was an XSDObjectGen (or something like that) but that tool seems to have vanished from the face of the cyberspace :-(

有一个XSDObjectGen(或类似的东西),但这个工具似乎已经从网络空间消失了:-(

I saw one approach use XSDTidy to apply a sort of a replacement of all int[] into List over the output of the XSD tool - seems to have worked, but seemed a bit clunky.

我看到有一种方法使用XSDTidy将所有int[]替换为List,而不是XSD工具的输出——似乎有效,但似乎有点笨拙。

Here's a CodeProject article on XSDTidy.

这里有一篇关于XSDTidy的CodeProject文章。

The thing I've been trying to find again is a blog post by a gentleman who basically dissected the inner workings of XSD in Reflector, and then used the knowledge he gained on that to build his own tool, using a lot of .NET core classes. If I remember correctly, it was this blog post here ("writing your own xsd.exe"). Mike isn't exactly doing what you're looking for (creating List instead of arrays), but it could be a starting point.

我一直在寻找的是一位男士的博客文章,他基本上剖析了在Reflector中XSD的内部工作,然后利用他在此获得的知识来构建自己的工具,使用了许多。net核心类。如果我没记错的话,是这篇博客文章(“写你自己的xsd.exe”)。Mike并不是在做你想要的东西(创建列表而不是数组),但这可能是一个起点。

Marc

马克

#1


8  

Found this post when searching for an answer. I'm using this tool: http://xsd2code.codeplex.com/

在搜索答案时找到了这篇文章。我正在使用这个工具:http://xsd2code.codeplex.com/

#2


1  

The problem is that XSD is XML - language agnostic. It can't use anything from Java or C# that the other doesn't support. Arrays are the lowest common denominator.

问题是XSD与XML语言无关。它不能使用其他不支持的任何Java或c#。数组是最小公分母。

Java developers use OXM libraries like XStream to marshal objects to XML and back. It allows you to specify custom types when going from objects to XML. Sounds like you'll have to find something similar in the .NET toolbox.

Java开发人员使用诸如XStream之类的OXM库将对象编组到XML并返回。它允许您在从对象到XML时指定自定义类型。听起来你必须在。net工具箱中找到类似的东西。

This isn't an answer to your question, but it's the reason why I think XSD won't do the job. Like a Java developer reaching out to XStream, you'll have to look elsewhere.

这不是对您问题的回答,但这是我认为XSD不能胜任这个工作的原因。就像Java开发人员接触到XStream一样,您必须到别处寻找。

#3


1  

You've seen the ability to use collections with Service References, not with Web References. Look at the svcutil.exe utility instead. It looks like svcutil /t:code file.xsd might do this for you.

您已经看到了使用服务引用来使用集合的能力,而不是使用Web引用。看看svcutil。exe实用程序。它看起来像svcutil /t:代码文件。xsd可能为您实现这一点。

#4


1  

I am not aware of any tools out there at this time that do this reliably, unfortunately.

不幸的是,目前我还不知道有什么工具可以可靠地做到这一点。

There was an XSDObjectGen (or something like that) but that tool seems to have vanished from the face of the cyberspace :-(

有一个XSDObjectGen(或类似的东西),但这个工具似乎已经从网络空间消失了:-(

I saw one approach use XSDTidy to apply a sort of a replacement of all int[] into List over the output of the XSD tool - seems to have worked, but seemed a bit clunky.

我看到有一种方法使用XSDTidy将所有int[]替换为List,而不是XSD工具的输出——似乎有效,但似乎有点笨拙。

Here's a CodeProject article on XSDTidy.

这里有一篇关于XSDTidy的CodeProject文章。

The thing I've been trying to find again is a blog post by a gentleman who basically dissected the inner workings of XSD in Reflector, and then used the knowledge he gained on that to build his own tool, using a lot of .NET core classes. If I remember correctly, it was this blog post here ("writing your own xsd.exe"). Mike isn't exactly doing what you're looking for (creating List instead of arrays), but it could be a starting point.

我一直在寻找的是一位男士的博客文章,他基本上剖析了在Reflector中XSD的内部工作,然后利用他在此获得的知识来构建自己的工具,使用了许多。net核心类。如果我没记错的话,是这篇博客文章(“写你自己的xsd.exe”)。Mike并不是在做你想要的东西(创建列表而不是数组),但这可能是一个起点。

Marc

马克