Customising the names of closed generic types in data contracts

Say I have a type:

struct Range<T>{
T Min;
T Max;
}

[DataContract]
class MyData {
[DataMember]
Range<DateTime> Range;
}

svcutil generates something like RangeOfDateTimeOl1JJNb3

Is there any way to to configure that instances of type Range<DateTime> should be exported as (say) DateTimeRange

Thanks.



Answer this question

Customising the names of closed generic types in data contracts

  • StatlerW

    You can dictate your own generic type parameter name using

    the {<number>} syntax, where the number of type parameters verified at load time. You can use {#} for the hash that the tool generates for you (if you want that).

    In your case, that would be

    [DataContract(Name = "Range{0}")]
    class Range<T>
    {...}

    Thanks,

    Juval Lowy, IDesign Inc.


  • Customising the names of closed generic types in data contracts