这就是我想要实现的目标:
config.Name("Foo")
.Elements(() => {
Element.Name("element1").Height(23);
Element.Name("element2").Height(31);
})
.Foo(23);
或像这样:
.Elements(e => {
e.Name("element1").Height(23);
e.Name("element2").Height(31);
})
.Foo(3232);
这就是我目前所拥有的:
public class Config
{
private string name;
private int foo;
private IList<Element> elements = new List<Element>();
public Config Name(string name)
{
this.name = name;
return this;
}
public Config Foo(int x)
{
this.foo = x;
}
... //add method for adding elements
class Element
{
public string Name { get; set; }
public int Height { get; set; }
}
}
有人知道该怎么做吗?