我想作一個靜態類,流暢的界面,但我得到的錯誤:返回「這」在靜態方法
'this' is not valid in a static property, method ...
這裏是我的代碼:
public static MyClass
{
private static StringBuilder builder;
private static StringBuilder RouteBuilder
{
get
{
if (builder == null)
builder = new StringBuilder();
return builder;
}
}
public static MyClass Root()
{
RouteBuilder.Append("/");
return this;
}
public static MyClass And()
{
RouteBuilder.Append("and");
return this;
}
public static MyClass Something()
{
RouteBuilder.Append("something");
return this;
}
}
這使我能做MyClass.Root().And().Something();
有沒有辦法做到這一點或解決方法?
你想要什麼'這個'在你的靜態方法? – jalf 2012-04-15 08:59:52
我寫了一篇關於流暢構建器接口的[博客文章](http://mattdavey.me/2012/03/08/practical-applications-of-the-adaptive-interface-pattern-the-fluent-builder-context/)最近可能會有所幫助 – MattDavey 2012-04-15 09:00:22