我正在尝试阅读这篇文章:http ://codebetter.com/gregyoung/2007/12/05/a-use-for-extension-methods/
到目前为止,我一直很好:
Now that I have these I can decorate the Builder with extension methods like:
public static CostBuilder Cost(this Builder s)
{
return new CostBuilder();
}
我在哪里粘贴这段代码?
编辑:每弗拉德的回答
我将这段代码卡在了 Builder 和 Create 类所在的位置
public static partial class BuilderExtensions
{
}
然后对于需要添加构建器的任何命名空间,我将其粘贴在同一类文件中的构建器类下方:
public static partial class BuilderExtensions
{
public static CostBuilder Cost(this Builder s)
{
return new CostBuilder();
}
}