I have a Static class which has a very large name which belongs to the same
Namespace as the class that I am working in. I want to create an "alias" for
this "big class name" so that I can save keystrokes and make the program more
readable. I am not sure how to do this globally within the class that I am
working.
Is there some way to do this?
So instead of typing
MyGiganticInformativeClassName.DoSomething()
I want to use
MGIC.DoSomething();
Aarthi - 18 Oct 2005 22:02 GMT
Unfortunately, I don't think you can. A work-around though. What about having
a static property in your class that just serves as a wrapper for this
gigantic class name
such as
class SClass
{
string SomeValue
{
get
{
return LognClassName.SomeValue;
}
set
{
LongClassName.SomeValue=value;
}
}
}

Signature
Aarthi R S
> I have a Static class which has a very large name which belongs to the same
> Namespace as the class that I am working in. I want to create an "alias" for
[quoted text clipped - 8 lines]
> I want to use
> MGIC.DoSomething();
Dirc Khan-Evans - 19 Oct 2005 09:26 GMT
> I have a Static class which has a very large name which belongs to
> the same Namespace as the class that I am working in. I want to
[quoted text clipped - 8 lines]
> I want to use
> MGIC.DoSomething();
Yes.. this is entirely possible using "Using alias directives"
From the documentation:
A using-alias-directive introduces an identifier that serves as an
alias for a namespace or type within the immediately enclosing
compilation unit or namespace body.
using-alias-directive:
using identifier = namespace-or-type-name ;
Within member declarations in a compilation unit or namespace
For more information take a look at the MSDN documentation.
Dirc
Dirc Khan-Evans - 19 Oct 2005 09:45 GMT
> I have a Static class which has a very large name which belongs to
> the same Namespace as the class that I am working in. I want to
[quoted text clipped - 8 lines]
> I want to use
> MGIC.DoSomething();
Of course the real question is why you decided to use a long name in
the first place and now want to use an alias?
Personally, I like long names if they are descriptive and helpful. If
you have used this name in the first case, I think it makes code more
readable and understandable if you use this name throughout your code.
Dirc
Aarthi - 19 Oct 2005 13:49 GMT
sorry..Two minutes after I posted this, I realized what Dirk has posted..you
can use something like
using AliasToMyClass = NameSpace1.MyClass;

Signature
Aarthi R.S
> I have a Static class which has a very large name which belongs to the same
> Namespace as the class that I am working in. I want to create an "alias" for
[quoted text clipped - 8 lines]
> I want to use
> MGIC.DoSomething();