在为一个类编写了另一个样板构建器之后,IDictionary<string, string>
我正在寻找一些以声明式样式执行它的库。这是我想要的一个例子。你能建议任何允许这样做的库吗?
class Person
{
string Name;
int Age;
}
class PersonBuilder
{
public Person Build(IDictionary<string, string> values)
{
// MagicBuilder is what I'm looking for
var magicBuilder = new MagicBuilder<Person>();
// MagicBuilder.AddRequiredField<Type>(key, field)
magicBuilder.AddRequiredField<string>("name", p => p.Name);
// MagicBuilder.AddOptionalField<Type>(key, field, defaultValue)
magicBuilder.AddOptionalField<int>("age", p => p.Age, 0);
return magicBuilder.Build(values);
}
}