作業中の単純なツール用の最初の DSL を作成しようとしています。ビルダー パターンを使用して複雑な親オブジェクトをセットアップしていますが、親オブジェクトの子コレクションを構築するためにレンガの壁にぶつかっています。サンプルは次のとおりです。
使用する:
var myMorningCoffee = Coffee.Make.WithCream().WithOuncesToServe(16);
クロージャー付きのサンプル(それが彼らの名前だと思います):
var myMorningCoffee = Coffee.Make.WithCream().PourIn(
x => {
x.ShotOfExpresso.AtTemperature(100);
x.ShotOfExpresso.AtTemperature(100).OfPremiumType();
}
).WithOuncesToServe(16);
サンプル クラス (子 PourIn() メソッドなしで、これは私が把握しようとしているものです。)
public class Coffee
{
private bool _cream;
public Coffee Make { get new Coffee(); }
public Coffee WithCream()
{
_cream = true;
return this;
}
public Coffee WithOuncesToServe(int ounces)
{
_ounces = ounces;
return this;
}
}
したがって、仕事用のアプリでは、複雑なオブジェクトをうまく構築できますが、親オブジェクトのサブコレクション用にコード化されたラムダを取得する方法を一生理解できません。(この例では、expresso の shots (子コレクション) です)。
おそらく、ここで概念を混乱させているのでしょう。しかし、私はこれがどのように読めるかが本当に好きで、これを機能させる方法を理解したいと思っています.
ありがとう、サム