Compiling C# for use into a VB application
-
13 มีนาคม 2555 13:35
Is there any way that I can compile a piece of C# code written on a file, then insert it in a function and run it(under VB.net)?
http://www.codeproject.com/Articles/1931/C-Compiler (is this any good?)
Muscalu Ștefan ~~~~ Student
ตอบทั้งหมด
-
13 มีนาคม 2555 14:06ผู้ดูแล
If you really MUST, you can compile the c# code into a DLL file, then you can make a reference to that DLL file and import it into your class....
Any particular reason you can't save yourself the trouble and just use one language(either c# or vb)?
There's plenty of free c# to vb translators out there... and the translation process is relatively painless....
Here's an example of one such site:
http://converter.telerik.com/
If you want something you've never had, you need to do something you've never done. If you believe something to be true, then one day you will be called upon to demonstrate that truth.
- แก้ไขโดย Paul IshakMicrosoft Community Contributor, Moderator 13 มีนาคม 2555 14:06
-
13 มีนาคม 2555 14:34
I am making a kind of debugger that goes line by line (of a user written code in C#) and displays current memory objects.
I once found a project that compiled a piece of code (user written) in VB and used it in a function but that was a long time ago and i can't find it anymore. :(
Muscalu Ștefan ~~~~ Student -
13 มีนาคม 2555 14:46ผู้ดูแล
You intend to use a code written in c#, with a vb project? if so....
It is very easy, you can create a new class library in c#, add your code(remembering that public things will be accessible from outside of your library).
You the build your solution, and in the output of your debug>bin folder will be a copy of your dll file.
If your VB project you go to the solution explorer window, and click "Add reference", navigating to the dll that is in the debug>bin folder of your c# class library project.
Now that you have added a reference, you import it..
Or do you simply need to evaluate the TEXT of a c# code?
in which case, you could simply open the file to a string
If you want something you've never had, you need to do something you've never done. If you believe something to be true, then one day you will be called upon to demonstrate that truth.
-
13 มีนาคม 2555 14:58
Looks like there is a misunderstanding.
Let’s say that I have a Form that contains a textbox.
A user inputs this code into the textbox
Int a=1,i; for(i=0;i<10;i++)a=a*10;
I need to compile the code that is in the textbox and use it in a function(run it inside a function in my application).
Can I do that?
Muscalu Ștefan ~~~~ Student -
13 มีนาคม 2555 15:43
No there is no C# scripting tool, because that is what you are asking.
Of course you can build a program using csc.exe
http://msdn.microsoft.com/en-us/library/78f4aasd.aspx
But that is not simply doing it scripting and needs more than just only the code you show.
The code can however not been used then in a VB build (assembly) be aware that it is the same for VB scripting or whatever kind of scripting..
Success
Cor- แก้ไขโดย Cor LigthertMVP 13 มีนาคม 2555 15:44
-
13 มีนาคม 2555 16:12ผู้ดูแล
Looks like there is a misunderstanding.
Let’s say that I have a Form that contains a textbox.
A user inputs this code into the textbox
Int a=1,i; for(i=0;i<10;i++)a=a*10;
I need to compile the code that is in the textbox and use it in a function(run it inside a function in my application).
Can I do that?
Muscalu Ștefan ~~~~ Student
That sounds like a job for codedom:
Heres a couple examples I found with a quick internet search:
http://www.codeproject.com/Articles/1931/C-Compiler (Compile C# in c#)
http://www.codeproject.com/Articles/5472/Compiling-NET-code-on-the-fly (Compile Vb in Vb)
You can easily twist either of these examples to compile either language as well, plus you can use a c#->Vb convertor or vb->C# converter to translate the code between languages.
If you want something you've never had, you need to do something you've never done. If you believe something to be true, then one day you will be called upon to demonstrate that truth.
- แก้ไขโดย Paul IshakMicrosoft Community Contributor, Moderator 13 มีนาคม 2555 16:18
- ทำเครื่องหมายเป็นคำตอบโดย Muscalu Stefan Gabriel 13 มีนาคม 2555 16:39
-
13 มีนาคม 2555 16:36
There is no "scripting" period. The code is SOURCE code.
Renee
"MODERN PROGRAMMING is deficient in elementary ways BECAUSE of problems INTRODUCED by MODERN PROGRAMMING." Me
-
13 มีนาคม 2555 16:41
Looks like there is a misunderstanding.
Let’s say that I have a Form that contains a textbox.
A user inputs this code into the textbox
Int a=1,i; for(i=0;i<10;i++)a=a*10;
I need to compile the code that is in the textbox and use it in a function(run it inside a function in my application).
Can I do that?
Muscalu Ștefan ~~~~ Student
That sounds like a job for codedom:
Heres a couple examples I found with a quick internet search:
http://www.codeproject.com/Articles/1931/C-Compiler (Compile C# in c#)
http://www.codeproject.com/Articles/5472/Compiling-NET-code-on-the-fly (Compile Vb in Vb)
You can easily twist either of these examples to compile either language as well, plus you can use a c#->Vb convertor or vb->C# converter to translate the code between languages.
If you want something you've never had, you need to do something you've never done. If you believe something to be true, then one day you will be called upon to demonstrate that truth.
Yes, the second link is the project that I could not remember of, thank you a lot!
Muscalu Ștefan ~~~~ Student