使用Automapper,Linfu,Clay或ImpromptuInterface

时间:2017-03-18 08:44:12

标签: automapper dynamic-proxy impromptu linfu clay

我需要从匿名类型,json或Dictionary

构造一个不可变复杂动态代理类

鉴于我有一个

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; }
}

以下任何一个来源

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'}" +
    "]" +
 "}"

有没有办法动态实例化和绑定IChangeDetails?

我已经探索过Linfu,ClaySharp,ImprpomtuInterface和AutoMapper

我看不出如何将复杂的子属性与任何绑定。 虽然AutoMapper似乎是最有前途和最直接的,但似乎不支持不可变接口。虽然我认为它使用了林福,所以我觉得这也应该是可能的。

0 个答案:

没有答案