开发者

SvcUtil generating custom intermediate list types - any way to just generate a generic list?

开发者 https://www.devze.com 2023-02-04 20:03 出处:网络
I\'m using svcutil to generate datacontract classes from an XSD.Here\'s a snippet from the XSD: <xs:element name=\"Fulfilment\">

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开发者_如何学JAVA that inherits from list, and using that?


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


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消