I have a class that inherits from LinkButton, and I want to hide OnClinentClickfrom my class.
LinkButton
OnClinentClick
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
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.
new
NotSupportedException
You can use EditorBrowsableAttributeit to prevent IntelliSense from using it, but you cannot completely get rid of it.
EditorBrowsableAttribute
[EditorBrowsable(EditorBrowsableState.Never)] public virtual string OnClientClick { get; set; }
# . , . .
, . protected internal , . , , . . , LinkButton .
protected
internal
, . .
has-a is-a. .. , , . , , , .
setter NotSupportedException. , , . , ObsoleteAttribute.
ObsoleteAttribute
(.. , ), , 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 ).