I need to construct an Immutable Complex Dynamic Proxy class from an anonymous type, json or Dictionary

Given I have a

public interface ICommand
{
    Guid AggregateId { get; }
}

public interface IChangeDetails : ICommand
{
    Name Name { get; }
    Phone[] Phones { get; }
}

public class Name
{
    public string First { get; }
}

public class Phone {
    public string Number { get; }
}

And a source of any of the following

var annonSource = new{
    AggregateId = "6420B195-0F0B-4E88-AAEF-C7CDAF91A784",
    Name = new { First = "John" },
    Phones = new []{
        new { Number = "555-123456" }
    }
};

var dictSource = new Dictionary<string, object>{
    {"AggregateId", "6420B195-0F0B-4E88-AAEF-C7CDAF91A784"}
    {"Name.First","John"},
    {"Phones[0].Number", "555-123456"}
 }

 var jsonSource = "{" +
    "'AggregateId': '6420B195-0F0B-4E88-AAEF-C7CDAF91A784'," +
    "'Name': {" +
         "'First': 'John'" +
    "}," +
    "'Phones': [" +
        "{'Number': '555-123456'}" +
    "]" +
 "}"

Is there any way to dynamically instantiate and bind IChangeDetails ?

I have explored Linfu, ClaySharp, ImprpomtuInterface and AutoMapper

I could not see how to bind complex child properties with any. While AutoMapper seemed to be the most promising and straight forward but does not appear to support immutable interfaces. Although I believe it uses Linfu under the covers, so I feel this should be possible too.

0

There are 0 best solutions below