There is a base class (black box, it cannot change it) from which I get. In my derived class, I no longer want to allow users to use the property, instead I have a public function instead. I will not go into details of why (it does not matter), but here is the property that I am trying to hide:
public ComboBoxItemCollection Items { get; }
I tried this, but this did not work:
private new ComboBoxItemCollection Items { get; set; }
I also tried this, however the compiler says that I am not allowed to close both accesses:
public new ComboBoxItemCollection Items { private get; private set; }
How to do it right? Please note that I am not dependent on the fact that this is a complete security solution, obviously, thanks to casting the base class, they can still call this property. It simply means offering the user a compile-time error that helps them understand that they cannot use this property and should instead use a new function in the derived class.
EDIT
Thanks to the answers in this thread, I came up with the following solution:
[Obsolete( "This property is obsolete. Please use MRUIdComboBox.AddItem() instead.", true )] public new ComboBoxItemCollection Items { get { throw new NotSupportedException( "This property is not supported. Please use MRUIdComboBox.AddItem() instead." ); } }
source share