How to share the "using" in multi-files? [duplicate] - c#

This question already has answers here:
C#: Same "using" in multiple files
(2 answers)
using directive with whole program scope
(3 answers)
Closed 3 years ago.
I want to wrap some c\c++ dll to c#, and need to write some "using" statement to transfor some types, such as
using FoorInteger = int;
But it only works in single file. I must copy it to the other files.
How to make it works in multi-files just like the "#define " in c\c++ headers?

It works in C/C++ because of the #include directive, which tells the compiler "take everything from this other file and put it in this file". So any #define statements you have in the file you included are also defined in the file that has the #include directive.
There is no such thing in C#. There are other preprocessor directives that are similar to C/C++, but no #include. Since you cannot "include" another file, so there is no way to tell the compiler to include the using directives from another file.
You will need to copy the using directive to every file that uses it.

Related

Explaination of this "global" if statement that shows up in multiple files? [duplicate]

This question already has answers here:
What does hash sign # do in the C# especially in if-else Statements?
(2 answers)
Closed 4 months ago.
I am trying to figure out how to disable this IF statement so the code doesn't run unfortuanately I dont know what this IF statement is called so Im having trouble googling it.
I have tried searching for solutions online and looking in files.
That's a C# conditional compilation directive.
If you right-click on your project in Solution Explorer and go to Build > General > Conditional compilation symbols, you'll see the 'symbols' that are set and can be used in those #if statements. Typically you configure different symbols depending on the type of build you're running.

Call native C++ function from C# [duplicate]

This question already has answers here:
Is it possible to embed C code in a C# project?
(4 answers)
Closed 6 years ago.
I have C++ legacy code with functions in the form:
double func(double)
I have this as a source file - it isnt in the form of a DLL although it could be turned into one if necessary
How can I call func in my C# code (maybe over managed C++)? I heard of Marshalling and DllImport but I did not find MSDN very helpful.
You have to compile C++ code as DLL library and then DllImport is way to go.
I don't know what problem you have with it. On MSDN I found this https://msdn.microsoft.com/en-us/library/e59b22c5.aspx
And also this article: http://www.mono-project.com/docs/advanced/pinvoke/ seems to be quite useful.

Transform *.dll to *.cs [duplicate]

This question already has answers here:
How do I decompile a .NET EXE into readable C# source code?
(9 answers)
Closed 7 years ago.
I have a dll file that I want to decompile. I know there are ILSpy, dotPeek and similar programs, but I have yet to find one that will actually create the cs file.
The dll I'm dealing with has several hundred classes in it and it would take days to manually copy everything.
Is there a tool that will take a dll file and return a set of cs files?
ILSpy
If you have loaded a dll in ILSpy, select File -> Save Code... or type Ctrl + S.
If you select the dll in the tree, then it will create a cs
project in a selected folder, along with C# files for each
class.
If you select just a class in the tree, it will create just
the C# file for the class.
See ILSpy.

Adding resources and setting Exe description [duplicate]

This question already has an answer here:
How can we add embedded resources to a file which is compiled from a source file at run-time
(1 answer)
Closed 9 years ago.
I am generating C# code at runtime and compiling it with the CSharpCodeProvider The two problems I'm having are
How to add resources to the generated exe?
How to set the executable description (i.e company name and others) to it?
Thanks.
Have a look here my friend. I think this will sort you out as the guy was having the very same issue:
How can we add embedded resources to a file which is compiled from a source file at run-time

C# #define keyword available project wide [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
C#: Declare preprocesor symbol (like DEBUG) globaly for whole project
Can I set up a #NOTEMBEDDED definition in a project so that when I'm debugging and I hit a
#if NOTEMBEDDED
#endif
in various source files it will acknowledge it and fall into the if statement?
Add it to the project settings, right-click on the project, select Properties, under the Build tab there's a "Conditional compilation symbols".
You enter your conditional there.
Go to the Build tab in Project Properties and add it to the Conditional compilation symbols box.

Categories