public abstract class ExeCommand
{
private static object commandHandler;
public static object CommandHandler
{
get { return commandHandler; }
set { commandHandler = value; }
}
}
class ServerCommand : ExeCommand
{
}
This is the bare bones of it.
I want to allow
ExeCommand.CommandHandler = myCommandHandler
but not
ServerCommand.CommandHandler = myCommandHandler
Any way to enforce this?
It’s unclear what you are trying to achieve here.
You could prevent
ServerCommand.CommandHandlerfrom being writable by declaring the same property but hiding the setter, as Cory points out, but why? The caller could always just useExeCommand.CommandHandlerto assign a value. ServerCommand shares the static members from its base class.Perhaps if you could explain what you are trying to achieve a better design could be proposed.