I want to use a custom aplified type (think Nullable) in a DataContract class.
I tried to write a IDataContractSurrogate
but it fails at deserialization.
My amplified type looks like this:
public struct Amplified<TValue>
{
public TValue Value { get; set; }
//... some special code ...
}
And a DataContract may look like this:
[DataContract] public class MyDTO
{
[DataMember] public Amplified<string> SpecialString { get; set; }
}
The above code works but produces unnecessary nesting with the Value property of amplified type. I want the DataContract to represent the Ampliefied just as a normal string on the wire.
Is this possible with the DataContract Serializers (JSON & Xml)? Why do i get a InvalidCastException when using IDataContractSurrogate to replace Amplified with string?