As I assume static methods shouldn't be writen like the first snippet , or am I wrong ?
public static class ExtensionClass
{
private static SomeClass object1;
private static StringBuilder sb;
private static string DoSomething()
{
sb.AppendLine(object1.SomeValue);
}
public static string ExtensionMethod(this HtmlHelper helper, SomeClass _object1)
{
object1 = _object1;
sb = new StringBuilder();
DoSomething();
return sb.ToString();
}
}
So I come up with this:
public static class ExtensionClass
{
private static string DoSomething(ref StringBuilder _sb,SomeClass object1)
{
_sb.AppendLine(object1.SomeValue);
}
public static string ExtensionMethod(this HtmlHelper helper, SomeClass _object1)
{
SomeClass object1 = _object1;
StringBuilder sb = new StringBuilder();
DoSomething(ref sb,_object1);
return sb.ToString();
}
}
Is this last snippet multithread safe ? This should be an extension method,so it cant be non-static. Or is there any better way of passing non-static object in a static method around ?