SvcUtil 生成自定义中间列表类型 - 有什么方法可以生成通用列表?

发布于 2024-10-12 02:42:45 字数 916 浏览 1 评论 0原文

我正在使用 svcutil 从 XSD 生成数据契约类。以下是 XSD 中的片段:

<xs:element name="Fulfilment">

....
....
    <xs:element name="Products" minOccurs="0" maxOccurs="1">
      <xs:complexType>
         <xs:sequence>
             <xs:element minOccurs="0" maxOccurs="unbounded" 
                     type="Product" name="Product" />
         </xs:sequence>
      </xs:complexType>
    </xs:element>

生成的代码如下

 public ProductsType Products
        {
            get
            {
                return this.ProductsField;
            }
            set
            {
                this.ProductsField = value;
            }
        }

     public class ProductsType : System.Collections.Generic.List<Product>
     {
     }

:有什么方法可以让 svcutil 直接生成 Products 属性作为产品的通用列表,而不是创建从 list 继承的“ProductsType”类并使用它?

I'm using svcutil to generate datacontract classes from an XSD. Here's a snippet from the XSD:

<xs:element name="Fulfilment">

....
....
    <xs:element name="Products" minOccurs="0" maxOccurs="1">
      <xs:complexType>
         <xs:sequence>
             <xs:element minOccurs="0" maxOccurs="unbounded" 
                     type="Product" name="Product" />
         </xs:sequence>
      </xs:complexType>
    </xs:element>

Instead of the <Products> elements being generated as a list property of the Fulfilment object, the code that gets generated is this:

 public ProductsType Products
        {
            get
            {
                return this.ProductsField;
            }
            set
            {
                this.ProductsField = value;
            }
        }

     public class ProductsType : System.Collections.Generic.List<Product>
     {
     }

Is there any way to make svcutil generate the Products property as a generic list of products directly, rather than creating the "ProductsType" class that inherits from list, and using that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

花心好男孩 2024-10-19 02:42:45

svcutil.exe http://localhost/Services/Sample.svc?wsdl /ct :System.Collections.Generic.List`1 如果这是您想要的答案,请勾选

There you go svcutil.exe http://localhost/Services/Sample.svc?wsdl /ct:System.Collections.Generic.List`1 If this is the answer you want, please tick

风吹过旳痕迹 2024-10-19 02:42:45

是的,当您在 VS 上添加服务引用时,您可以决定如何从 WCF 转换集合。

Yes, when you add a service reference on VS you can decide how to convert a collection from WCF.

緦唸λ蓇 2024-10-19 02:42:45

请参阅 http://msdn.microsoft.com/en-us/library/aa347850 .aspx 有关集合序列化的详细讨论。

我问了一个类似的问题(svcutil 生成的代码中嵌套通用集合类是否有原因?)以及该 MSDN 文档为我回答了。只要您想使用 svcutil,似乎您就会陷入冗余的内部类中。我的结论是,由于它生成的代码和消费者的接口在这两种情况下都是相同的,所以我不会关心那个额外的类。

See http://msdn.microsoft.com/en-us/library/aa347850.aspx for a detailed discussion of serialization of collections.

I asked a similar question (Is there a reason for the nested generic collection classes in svcutil generated code?) and that MSDN document answered it for me. As long as you want to use svcutil, it appears you are stuck with the redundant internal class. My conclusion was that since it's generated code and the interface for the consumer is identical in both cases, I'm just going to not care about that extra class.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文