I have created the following class:
using System.Windows;
using System.Windows.Input;
using MyUtils.MyArgParser;
namespace MyUtils.MyImplement
{
public static class ImplementExitOnEscape
{
#region ImplementExitOnEscape
public static void Implement(Window window)
{
window.KeyDown += Window_KeyDown;
}
private static void Window_KeyDown(object sender, KeyEventArgs e)
{
var window = sender as Window;
// Close window when pressing the escape key.
if (e.Key == Key.Escape) if (window != null) window.Close();
var optionX = MyArgParser.MyArgParser.GetOptionValue("optionX");
}
#endregion //ImplementExitOnEscape
}
}
Why am I forced to use the full name space for the MyArgParser class in var optionX = MyArgParser.MyArgParser.GetOptionValue("optionX"); instead of just MyArgParser.GetOptionValue("optionX");?
using MyUtils.MyArgParser; gets ignored. having it there or not wouldn’t make any difference, the compiler still forces me to use the full namespace.
I find this weird because it is not happening everywhere. For example, I am not required to use the full namespace in the file where the entry point of my application is defined.
You class is named as your namespace, so to distinct between them you need to explicitly fully reference it.
To solve it, either change your MyArgParser namespace to (for example) MyArgParserNS and you can use it directly
And then:
Or, well, fully reference it.