They are class variables. In C #, there is nothing like an instance variable of the Smalltalk class. That is, there is no way to define a variable that is common to all instances of the class, but which has different meanings for its subclasses.
To get a “similar” behavior, but with the disadvantage that the var class instance is only available after creating an instance of your class, I did something like this:
public class BaseClass
{
private static Dictionary<Type, object> ClassInstVarsDict = new Dictionary<Type, object>();
public object ClassInstVar
{
get
{
object result;
if (ClassInstVarsDict.TryGetValue(this.GetType(), out result))
return result;
else
return null;
}
set
{
ClassInstVarsDict[this.GetType()] = value;
}
}
}
public class DerivedClass1 : BaseClass
{
}
public class DerivedClass2 : BaseClass
{
}
source
share