womp
womp

Reputation: 116987

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

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?

Upvotes: 0

Views: 1738

Answers (3)

Colin Young
Colin Young

Reputation: 3058

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.

Upvotes: 0

Raffaeu
Raffaeu

Reputation: 6993

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

Upvotes: 3

Raffaeu
Raffaeu

Reputation: 6993

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

Upvotes: 0

Related Questions