abstract class DirectiveNode
{
public static readonly RequirementOptions ArgumentOptions = RequirementOptions.Optional;
}
class IfNode : DirectiveNode
{
static IfNode()
{
ArgumentOptions = RequirementOptions.Required; // error here
}
I don’t understand the problem. I thought static IfNode() was a static constructor? Why the error?
Just found this: Assigning to static readonly field of base class
Unlike nonstatic constructors, a subclass’s static constructor has no relationship with the parent static constructor. If you want the subclass to be able to change the ArgumentOptions value used by base class functions, consider a virtual property: