I'm looking for a way to do the following:
class BaseClass
{
public enum Action
{
NO_ACTION
}
protected virtual bool ValidateAction(Action a)
{
return true;
}
}
class DerivedClass : BaseClass
{
public new enum Action
{
ACTION1,
ACTION2
}
protected override bool ValidateAction(Action a)
{
//... validate Action ...
}
}
The above doesn't work because by declaring my enum Action
as new
in the derived class I've created a totally new type; thus the compiler complains that I shouldn't be trying to override ValidateAction
in DerivedClass.
Basically I want to avoid having to use protected bool ValidateAction(int)
as my function prototype, thereby avoiding having to cast my enum values to ints all the time to make the call to ValidateAction
. Also, this would allow me to call ValidateAction
from BaseClass
and be sure that my virtual method in DerivedClass
gets called. Is there an obvious way of doing this that I am missing? Deriving from System.Enum
to create an Action
base class would do the trick, but I've read somewhere that this is poor practice. Any other suggestions?