Hide virtual function in inherited class

I have a class that inherits from LinkButton, and I want to hide OnClinentClickfrom my class.

Something like that:

public class MyClass : LinkButton
{
    // some Code
}

And somewhere in the code:

MyClass myclass = new MyClass();
MyClass.OnClinentClick = "";//this line must not be accessable
+3
source share
4 answers

Hiding something from a class definition is not directly supported because it violates OOP principles.

You can use the operator new, however I would not recommend it. Personally, I thought about my design and / or used NotSupportedExceptionif there is no other way.

+6
source

You can use EditorBrowsableAttributeit to prevent IntelliSense from using it, but you cannot completely get rid of it.

[EditorBrowsable(EditorBrowsableState.Never)]
public virtual string OnClientClick { get; set; }

# . , . .

+4

, . protected internal , . , , . . , LinkButton .

, . .

has-a is-a. .. , , . , , , .

setter NotSupportedException. , , . , ObsoleteAttribute.

0

(.. , ), , new, .

Update:
in fact, you cannot change access from the public to protected / private when overriding, this will not compile ( http://ideone.com/Y65Uh ). Also, if you use newto hide the underlying function and make it unrecoverable, the original function will still be visible ( http://ideone.com/xiL2F ). If you declare a new public function (which may not be what you want), you can still call the old function by casting it to the base class ( http://ideone.com/A3Bji ).

0
source

All Articles