Long Class Name

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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();
 
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;
}

}
}
 
Jim said:
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();

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

--
 
Jim said:
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();

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

--
 
sorry..Two minutes after I posted this, I realized what Dirk has posted..you
can use something like
using AliasToMyClass = NameSpace1.MyClass;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top