Search code examples
c#wcfdatacontractdatamember

Is there a way to decorate multiple properties with DataMember in a data contract in WCF?


I've got a basic WCF service. I've split out my data contracts and one of them is a class with a large amount of public properties. If I want to make these properties available to the client I'm assuming all of these will need to have [DataMember]. So, as there's a large number of these properties, is there any way of bulk decorating them with [DataMember]? something like:

[DataMember]
(
    public string Title { get; set; }
    public Guid ID { get; set; }
    public Description { get; set; }

    //more properties...
)

I've only ever seen:

[DataMember]
public string Title { get; set; }
[DataMember]
public Guid ID { get; set; }
[DataMember]
public Description { get; set; }

Solution

  • No, unfortunately, it's not possible to mark the group of properties with the attribute.