I would ask if its Possible to use Settings with Codedom like this
Example:
Write settings to Fresh Generated Executable file ,like Resources or something smiliar.
I have searched on msdn but didnt find something.
Not directly with CodeDom. As its name suggests, Code Dom is about, well, code, and what you can do with it. You can in theory generate an assembly via CodeDom, and then manipulate it using other libraries to embed the resources on it.
Related
I have a Java code editor with syntax highlighting, with a code hint menu and quick actions. The editor is written in C#. Once again, this editor is for editing Java code! I need to know what packages, classes, methods are in the Jar library (Jar file) for further
code hinting and syntax highlighting.
I have an idea about decompiling the Jar to find out "its contents", but I suspect that there is another more efficient way to implement this.
This is what my editor looks like:
It turned out to be relatively simple. I found the 'jd-gui' repository (https://github.com/java-decompiler/jd-gui), here is the app: (http://java-decompiler.github.io/). The program itself is written in java and is a very good java decompiler based on the jd-core core (https://github.com/java-decompiler/jd-core).
I liked this application, because. it implements a detailed overview of the entire decompiled application (you can see what packages, classes, methods, fields are in the jar), that's exactly what I needed! Because it was an open source repository, I just tweaked it a little, and now when decompiling, the program saves the xml file with the "contents of the jar file". And then I wrote an xml parser in c# to load data and further work with them. That's all...
Code with edited jd-gui saving xml file with jar content: https://drive.google.com/drive/folders/1_opg0BBIrmHoZ125F0Fyl9n_0o4xutiL?usp=sharing When loading a jar file, next to it (in the same folder) an xml file with the contents of this file will be saved.
Can anyone tell clearly about the usage of header files and namespaces in C#?
Because in C++ I was using ******.h files to read library functions. And when I saw some sample programs in C# they were missing, Can anyone tell me why?
I'm using C# to develop a custom tool for a CAD application. Whenever I use the appropriate function to open the file (CAD file), the compiler is giving me an error stating that the function names which I supply are not available in the context. Here what does meant by context?
When I opened the help file of that CAD application the function which is responsible for opening the file has bee mentioned under a header file called uf_part.h. But there is an namespace called NXOpen.
I used the namespace as using NXOpen in Visual Basic, isn't that enough? DO I need to supply that header file as well? If so, how?
C# is more "programmer friendly". When dealing with files of the same project, instead of manually specifying "header file" every time, it will go and look in all the project files for a match according to the namespace.
To understand this, do the following steps:
Start new project in Visual Studio. (No matter what type, WinForms or Console)
Right click the project and add new class.
In your main class note you can see the new class you just added, without adding any header.
How this is done? Simply by having the same namespace to both classes. The .NET engine is smart enough to link all those classes together.
Now, when it comes to external code meaning code sitting in a different DLL file the trick is to add reference to that DLL (in Studio --> Right click project --> Add reference --> Browse) then you need to specify you are going to use that DLL by adding a using statement on top:
using ExternalDllName.ExternalNamespace;
That's about it. Unlike C++ you don't need to have .h file as .NET will automatically search the referenced DLL files for a match.
There's no such thing as header file in .net, because all needed metadata is contained in referenced assembly itself.
Have you referenced needed assembly in you project?
Also please mind that there's no such thing as "function" in C#, only class methods (which means that you have to specify object or static class in you call).
Also: General Structure of a C# Program
Compilers for modern languages, such as C# or Java store within compiled files information on the classes and methods they contain, and this information can be used to check the correctness of calls made from one source file to another or to library classes.
When C was invented disk space, memory and CPU power were precious resources and this approach would not have been possible. Header files were introduced to allow the compiler to check that different source files conformed to the same interface. When C++ was invented the approach described above could have been possible, but I guess that it was chosen to stick to the C one for compatibility reasons.
Hi I do not know if this is possible or not but I have a c# Project lets say A and I am trying to access Assembly Info of another project B so that i can get Method Info of project B using Reflection. Problem is that i can not think of a way to integrate those two. Project A provides a openFileDialogue and it selects .csproj file. Reads it and extracts what files are being used in project B.
Can you suggest me a work out?
I don't think you can do that by using reflection. To work with reflection you'll need an assembly, not csproj (or cs files). You should look for a parser, maybe use the Roslyn APIs, that will give you information about the source code in syntax tree format.
http://blogs.msdn.com/b/visualstudio/archive/2011/10/19/introducing-the-microsoft-roslyn-ctp.aspx
Each .csproj file is XML, so you can read that in pretty easily. Listed in that file is every file included in the project, so you can parse the XML .csproj file to find all the .cs files.
From there, if you need to extract MethodInfo, you would have to either parse the .cs files, or use something like Roslyn to parse the code into its syntax tree, and find the methods that way.
Can you just use the built assembly (.exe or .dll) from "Project B" instead of its .csproj file? It would be a lot easier to load the assembly's reflection info, and just loop over every class and evey method...
Use Assembly.LoadFile to load directly the compiled assembly - i.e. the DLL or EXE; this will give you an Assembly object on which you can call GetTypes() etc. to access all the info you want.
Recently I've been working with MSTest, and I noticed that the testframework generates accessor classes dynamically at compile time. How can one do this?
There's an xml file in a VS2010 C# project. I'd like to make an enum out of certain data in this xml file. Can this be done? And if so, how?
I'd recommend T4 templates myself. Very easy to use and specifically designed to allow you to generate code during the build. http://msdn.microsoft.com/en-us/library/bb126445.aspx
Method A) Read the xml file, parse it, generate C# code from it, write out the C# code to a temp file, compile that code; delete the temp file.
Method B) Read the xml file, parse it. Generate IL code directly from it using method in the System.Reflection.Emit namespace, or those in the System.CodeDom namespace.
MSTest achieves this in a couple of different ways. In short they essentially do the following IIRC
Hook into the build system
At the start of the build they generate their acessor's into hidden files in the project
After the build completes they remove their files
You can achieve a similar effect via the same process. However hooking into the build system is a bit complicated. A much simpler approach is to build a custom tool / code generator and hook. This allows you to process a file at build time and spit out a corresponding code file to include in the build.
There are several examples on the web on how to achieve this. Here are a couple
http://www.raboof.com/Projects/VsCodeGeneratorShim/
http://www.ramymostafa.com/?p=204
The System.CodeDom Namespace is one option you have.
It allows you to automatically generate a class using C# Code and compile it as well.
You can maybe call this code as a postbuild during your build of your project.
This example shows how to create a class using this namespace
I know we have ILdasm, but is there any tool out there that will let me edit .exe or .dll files without having to go through all the rigmarole of having to convert it to IL code, with resources includeded, etc etc, manually edit, then recompile again?
You could always use Reflector to disassemble whole namespaces to source code (not IL), but then you're still stuck without a direct editor, you have to copy/paste to a code file and recompile.
On the other hand, it seems like I was wrong, Reflector has an add-in Reflexil that looks like it'll do what you want.
check out this SourceForge project I guess it's what you're looking for:
http://sourceforge.net/projects/dile/
Perhaps you should check out Mono.Cecil. It's a managed library for manipulating IL. You can add, remove and modify methods as you please.
Granted it's not an IDE or anything but it should be a starting point.