C # using application application area

I have a question about the using statement for multiple files at once.

I created overloading for the class that I want to use in my program. To do this in one of my files, I added the following using statement.

 using ClassName = CustomClassName; 

This works, but only for this particular file.

Is there a way to make this work for my entire project?

+4
source share
4 answers

This is called type smoothing; reusing the using keyword can be misleading, but it is not an import.

The purpose of this statement is to make a particular class available with a different name. This is useful in cases where you have different assemblies associated with your project that accidentally have classes with the same name.

If you, for example, have A.dll that defines the class Foo in the namespace A and the assembly B.dll , which also defines the class Foo in the namespace B , you can use:

 using FooA = A.Foo; using FooB = B.Foo; 

to make a difference between the two.

The volume of this is usually the current file, although if you manage to define several namespaces in one file, you can specify the scope in the file:

 using FooA = A.Foo; namespace N1 { // knows about FooA; using FooB = B.Foo; } namespace N2 { // knows about FooA // does not know about FooB } 

In practice, you can make this alias more specific, but not wider than the scope of the file.

+2
source

No.

using directives for each file.

You can always create a template that includes it.

+6
source

No; C # does not have such a function.

+4
source

A simple solution for this is to create a template and use it in a project or class. this will give you the opportunity to use desires and desire directives as you wish.

here is a good sample for creating a template.

http://www.rhyous.com/2010/02/17/how-to-modify-the-default-new-class-template-in-visual-studio-2008/

http://visualstudiomagazine.com/articles/2008/09/01/define-your-own-item-templates.aspx

+2
source

Source: https://habr.com/ru/post/1484407/


All Articles