0

I have my own window in which I have my own ShowDialog method. Now I would like to hide the inherited ShowDialog methods. Since my method is different from the inherited one (it is returning string and accepting two other strings as parameters), override can not be used. Hiding from Intellisense is not enough, I want Intellisense to show other programmers error of a non-existing method when they try to open my window with MyWindow.ShowDialog();, they should strictly use it with MyWindow.ShowDialog("string1", "string2");. How can this be achieved? Or you have some other ideas, since the reason for this is that other programmers know how my window is used before they compile it, thus saving some of their time.

Adder
  • 165
  • 1
  • 14

1 Answers1

1

if you want developers to use but warns them for the method depreciation use ObsoleteAttribute attribute.If you want to hide method from them, use EditorBrowsable attribute.

[ObsoleteAttribute("you cannot use this method use ShowDialog(string,string) instead", true)] 
new public void ShowDialog()
{
     base.ShowDialog();
}

or

[ObsoleteAttribute("Depreciated, use ShowDialog(string,string) instead", false)] 
new public void ShowDialog()
{
     base.ShowDialog();
}

or

[EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
new public void ShowDialog()
{
    base.ShowDialog();
}
FreeMan
  • 1,417
  • 14
  • 20
  • Then my new `ShowDialog()` would show up, I want to hide it. – Adder Sep 21 '16 at 09:06
  • "editorbrowsable only hides the method if you're just importing the dll, not if you're referencing another project in the solution" - http://stackoverflow.com/questions/9086136/how-to-hide-public-methods-from-intellisense/9086419#9086419 – stuartd Sep 21 '16 at 10:01
  • yes, `[EditorBrowsable]` did not hid it, but `[Obsolete]` is showing warning upon usage, so it is something. Still looking for complete removal, but this will be marked as answer in case no one manages to remove it. – Adder Sep 21 '16 at 11:42
  • If you set false in Obsolete attribute, noone can use the method, if set true , it warns but you can use as it is depreciated. – FreeMan Sep 21 '16 at 11:52