Can I create an alias in C # or VB.NET in the method scope?
3 answers
While this might be overkill, you can create a partial class and only place the functions you want the alias to apply in its own aliased file.
In the main class file:
/*Existing using statements*/
namespace YourNamespace
{
partial class Foo
{
}
}
In another file:
/*Existing using statements*/
using C = System.Console;
namespace YourNamespace
{
partial class Foo
{
void Bar()
{
C.WriteLine("baz");
}
}
}
+3
a source to share
See here and here for more details.
Example:
namespace PC
{
// Define an alias for the nested namespace.
using Project = PC.MyCompany.Project;
class A
{
void M()
{
// Use the alias
Project.MyClass mc = new Project.MyClass();
}
}
namespace MyCompany
{
namespace Project
{
public class MyClass{}
}
}
}
0
a source to share