1

I am completely aware that we can have same namespace and the .NET Framework Namespace, and how to access the .NET framework namespace class, when the custom namespace is hiding it.

My question is if I have a custom namespace and class name same as .NET framework namespace and class name, how can I access the .NET framework namespace and class inside it? Example: If I create a C# project with System namespace and a class Console with two methods Read() and Write(), how will I be able to access the .NET framework namespace and console to display output..

Apologies for asking such type of question.. It my curiosity to know what happens in such cases.

Thanks

1
  • Thanks for the work around look good.. but i was looking for how i could use the .NET Console.WriteLine in my custom WriteLine() method under the custome Class System namespace System { public static class Console { public static void WriteLine(string s) { System.Console.WriteLine("in am in custome WriteLine method"); } } } Commented Mar 16, 2014 at 9:28

2 Answers 2

1

I tried using the extern alias method and actually couldn't get it to work. There is no way to do what you are asking for (Cunningham's Law).

As a workaround, you could just redirect the call as I have done below:

namespace System
{
    extern alias ActualSystem;
    //using SC = ActualSystem::System.Console;  
    //does not work:
    //Error 1   The type or namespace name 'Console' does not exist in the namespace 'ActualSystem::System' 
    //          (are you missing an assembly reference?)    
    using ClassLibrary;

    public static class Console
    {
        public static void Write(string s)
        {
            ConsoleRedirect.Write(s);
        }
    }
}

namespace ClassLibrary
{
    using System;
    public static class ConsoleRedirect
    {
        public static void Write(string s)
        {
            Console.Write(s);
        }
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the work around look good.. but i was looking for how i could use the .NET Console.WriteLine in my custom WriteLine() method under the custome Class System namespace System { public static class Console { public static void WriteLine(string s) { System.Console.WriteLine("in am in custome WriteLine method"); } } }
0

You can use external aliases in Visual Studio. Here is the description of the command line parameters.

1 Comment

but i was looking for how i could use the .NET Console.WriteLine in my custom WriteLine() method under the custome Class System namespace System { public static class Console { public static void WriteLine(string s) { System.Console.WriteLine("in am in custome WriteLine method"); } } }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.