I am trying to overload the unit operator ! in C # , so that it receives as a parameter a Visibility
. My goal is to reverse the visibility of a controller.
Example:
Button_Click(object sender, RoutedEventArgs e)
{
ControlName.Visivility = !ControlName.Visivility;
}
For this, I've done the following code.
namespace Test
{
//A namespace cannot directly contain a members such as fields or methods.
public static Visibility operator !(Visibility visibility)
{
if (visibility == Visibility.Visible) return Visibility.Hidden;
else return Visibility.Visible;
}
class VisivilityConverter
{
//The parameter of unary operator must be the containing type.
public static Visibility operator !(Visibility visibility)
{
if (visibility == Visibility.Visible) return Visibility.Hidden;
else return Visibility.Visible;
}
}
}
But I have these 2 errors:
- Error 1: A namespace can not directly contain a members such as fields or methods.
- Error 2: The parameter of unary operator must be the containing type.
If there is a way to do this, I hope someone can help me.