I structured my class like this:
public class MyList: List<MyClass>
{
internal static bool isConfigured;
// singleton
public MyList()
{
if (!MyList.isConfigured)
{
lock ("isConfigured")
{
if (!MyList.isConfigured)
{
// add some elements to MyList parsing them from an XML
[..]
MyList.isConfigured = true;
}
}
}
}
public static MyClass MyStaticMethod(int argument)
{
foreach (MyClass c in new MyList())
{
// do something
}
return // an instance of MyClass
}
}
When I call MyList.MyStaticMethod() from outside the singleton, I get the following exception:
[..]
MyClass mc = MyList.MyStaticMethod(1));
[..]
An object reference is required for the non-static field, method, or property 'MyList.get'
How can I solve this problem? What is the best why to lay down a singleton class based on List? Thanks
Like any other singleton.