Domanda

How could I avoid populating the ExtendedProperties collection in my data contract?

My WCF service is building the data contract from a XML and populating the ExtendedProperties with the properties that are not in the contract. Then they are returned and I would like to avoid that.

Clearing the ExtendedProperties collections is the straightforward approach but I was looking for a more elegant way to do that.

Any help?

È stato utile?

Soluzione

Using one of the other DataContractSerializer constructors that accept a boolean parameter named ignoreExtensionDataObject is the best way I have found to accomplish that.

public DataContractSerializer(Type type, 
    IEnumerable<Type> knownTypes, 
    int maxItemsInObjectGraph, 
    bool ignoreExtensionDataObject, 
    bool preserveObjectReferences, 
    IDataContractSurrogate dataContractSurrogate);

Altri suggerimenti

From MSDN Forward-Compatible Data Contracts:

The round-tripping feature may be turned off, either by setting ignoreExtensionDataObject to true in the DataContractSerializer constructor or by setting the IgnoreExtensionDataObject property to true on the ServiceBehaviorAttribute. When this feature is off, the deserializer will not populate the ExtensionData property, and the serializer will not emit the contents of the property.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top