【问题标题】:SvcUtil generating custom intermediate list types - any way to just generate a generic list?SvcUtil 生成自定义中间列表类型 - 任何方式来生成通用列表?
【发布时间】:2011-06-08 21:03:42
【问题描述】:

我正在使用 svcutil 从 XSD 生成数据契约类。这是来自 XSD 的 sn-p:

<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 属性生成为产品的通用列表,而不是创建从列表继承的“ProductsType”类并使用它?

【问题讨论】:

    标签: c# xsd code-generation svcutil.exe generic-list


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

      • 这不是服务参考,我使用命令行中的 svcutil 手动生成数据协定类。
      【解决方案3】:

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

      我问了一个类似的问题 (Is there a reason for the nested generic collection classes in svcutil generated code?),该 MSDN 文档为我回答了这个问题。只要您想使用 svcutil,您似乎就被多余的内部类所困扰。我的结论是,由于它生成的代码和消费者的接口在两种情况下都是相同的,我只是不关心那个额外的类。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-01-04
        • 2016-12-25
        • 1970-01-01
        • 1970-01-01
        • 2022-12-22
        • 2010-11-14
        • 1970-01-01
        相关资源
        最近更新 更多