You cannot do this in C#. Instead it might help you to use an abstract instance method and the Singleton Pattern:
abstract public class BaseClass
{
abstract public void RequiredStaticMethod();
}
sealed class Subclass : BaseClass
{
public static readonly Subclass Instance = new Subclass();
public void RequiredStaticMethod() {}
}
You might want to add a further description of the underlying problem you're trying to achieve. In general, you use abstract classes to decouple consumer from the actual implementation by making them use the abstract type instead. However, this cannot be done with static members, obviously. As Jon commented, I can't see how you're planning to consume BaseClass
yet.
You could maybe also use an interface, and find all implementing types via reflection. This would yield a typed iterable of IFoo
and invoke your method in an instance-bound fashion:
class Program
{
public static void Main()
{
var classes = Assembly.GetExecutingAssembly().GetTypes().Where(t => t.GetInterface("IFoo") != null);
foreach(var foo in classes.Select(c => Activator.CreateInstance(c)).Cast<IFoo>())
{
foo.RequiredNonStaticMethod();
}
}
}
public interface IFoo
{
void RequiredNonStaticMethod();
}
public class FooImpl : IFoo
{
public void RequiredNonStaticMethod()
{
Console.WriteLine("Foo");
}
}