Basically, as the title says:
[DataContract(Name = "{0}Item")] //This will format properly public class GenericItem<T> { [DataMember(Name = "The{0}")] //This will NOT format properly public T TheItem { get; set; } } [CollectionDataContract(Name = "{0}Items")] //This will format properly public SpecialCollection<T> : Collection<T> { } [ServiceContract(Name = "{0}Service")] //This will NOT format properly public interface IGenericService<T> { [OperationContract(Name = "Get{0}")] //This will NOT format properly GenericItem<T> Get<T>(); }
So, I have this ... that works and doesn't work ... but the question is ... why? Obviously, .NET can create a specific type and format for the name by using DataContract and CollectionDataContract and specifying the type (i.e. GenericItem<Foo> or SpecialCollection<Foo> ). So why not be able to format the DataMember ?
ServiceContract/OperationContract I can figure out how it stayed above (sorta), but I donβt understand when you give it a specific type, the operations will not work properly anyway:
[ServiceContract(Name = "FooService")] public interface FooService : IGenericService<Foo> { } public interface IGenericService<T> { [OperationContract(Name = "Get{0}")]
Again, why ? Obviously, I am declaring a specific Foo type here, which means that IGenericService is an IGenericService <Foo> so you should not format the name OperationContract, since it KNOWS the type?
Update:
I just remembered why I was upset that I could not use the fully formatted ServiceContract ... when I have a service implementation that I give it a specific type ...
I created a Microsoft Connect request. Promote it if you want this feature to be used for other attributes. http://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/2327048-enable-generics-for-datamemberattribute-serviceco
source share