7

I’m currently creating a .NET C# API. I have many classes, and some of them have to be transferred through a REST service as JSON. For example, I may have an account object with a lot of business meta-data:

public class Account
{
    public ComplicatedClass SomeProperty { get; set; }
    public string SomeOtherProperty { get; set; }
}

There are many classes, and many more that are nested (as demonstrated by ComplicatedClass type property). To avoid inundating this business-object with [DataMember] etc. Attributes that will make this class a mess, I want to make a DTO for JSON:

public class AccountDTOForJSON
{
    [DataMember(Name="someProperty")]
    public ComplicatedClassDTOForJson SomeProperty { get; set; }

    [DataMember(Name="someOtherProperty")]
    public string SomeOtherProperty { get; set; }
}

My problem is, there doesn’t seem to be any tools (that I can find) to auto-generate these DataContract classes, and also provide code for mapping properties back/forth.

I can, of course, do all this work manually (worst case), or roll my own tool to generate/map (second worse case). But, I’d like to know first if there’s already a tool to do this kind of thing that I can use to save myself time.