Definition problem

  • Thread starter Thread starter Abbiento Morgan
  • Start date Start date
A

Abbiento Morgan

How can i declare a definition with using (using a = b.c.d) and use it in
all files of my project without rewrite it in every file of my project ?
And if i want to permit the use of this alias to the user of my library ?
In C++ i use the #define instruction in a .h file and i include it in every
file i want to use alias. how can i do it in c# ?
 
Abbiento,

You can not do this. Includes (in the C++ sense), are not a feature of
C#. So, for every file, you will have to place the "using" directive there
yourself.

Hope this helps.
 
Nad ther'isnt solution for my problem ?

Nicholas Paldino said:
Abbiento,

You can not do this. Includes (in the C++ sense), are not a feature of
C#. So, for every file, you will have to place the "using" directive there
yourself.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Abbiento Morgan said:
How can i declare a definition with using (using a = b.c.d) and use it in
all files of my project without rewrite it in every file of my project ?
And if i want to permit the use of this alias to the user of my library ?
In C++ i use the #define instruction in a .h file and i include it in every
file i want to use alias. how can i do it in c# ?
 
Abbiento Morgan said:
Nad ther'isnt solution for my problem ?

I'd suggest that the best solution is to avoid doing the alias in the
first place. In general it's likely to reduce readability, as people
may be familiar with class named "d" but not "a" (if you see what I
mean).

I can't say I've ever used aliases in production code. (The only times
I've used them in test code is to investigate what they get can do.)
 
I cant think there isnt a solution for declare a global variable or a
global alias...

--------------------------
 
Morghan said:
I cant think there isnt a solution for declare a global variable or a
global alias...

There's a very good reason for it though - .NET is an object-oriented
platform, and "global alias" and "global variable" are not OO ideas.
 
Abbiento Morgan said:
Yes i know but sometimes there is very good reason for have global alias...

Such as? I haven't seen any examples which aren't clearer using a
singleton or whatever, myself.
 
An example can be when you must create an alias for permit to your user of
write most simple code instead of a list of nested class.
 
Abbiento Morgan said:
An example can be when you must create an alias for permit to your user of
write most simple code instead of a list of nested class.

But they can write a single using statement themselves at the top of
their own code. That way their code is more self-documenting. If they
need to understand where a particular alias comes from, it's right
there in their own code. In particular, they can also choose the alias
*they're* most happy with, rather than one *you've* picked.
 
Back
Top