我需要从匿名类型、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 似乎是最有前途和最直接的,但似乎不支持不可变接口。虽然我相信它在幕后使用了Linfu,所以我觉得这应该也是可能的。