Question

If I have a subclass that has yet to implement a function provided by the base class, I can override that function and have it throw a NotSupportedException. Is there a way to generate a compile-time error for this to avoid only hitting this at runtime?

Update: I can't make the base class abstract.

Was it helpful?

Solution

[Obsolete("This still needs implementing", true/false)] true if you don't want the build to succeed, false if you just want a warning

Slightly hackish ... but it does the job of warning at compile time.

OTHER TIPS

You can make the base class abstract:

abstract class Foo
{
    public abstract void Bar();
}

Now, any subclass must implement Bar(), or it won't compile.

Make it abstract with no implementation and fail to implement it in the derived class.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top