i was wondering how exactly I can create a small app that will accept my input and run it as code. same light as building an IDE, but I dont want to go that far, but I do want it to use the FCL. So like if I had a text box and i punched in:
string x = "hello";
int myLength;
myLength = x.length;
Then hit a submit button, it would compile this and run it into an output window. Is there a pretty simple way to do this? Or am i going to have to right a pretty involved method that breaks this all up? Sorry if i'm not being totally clear, I wasn't exactly positive on how to ask this question lol. Really what I'm getting at, is I want to create sort of a code "calculator" tool where I can punch in some simple snippets and test what it is returning without having to build a full class and compiling just to test something simple. can anyone point me in the right direction?
C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...
In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.
Compared to other languages—like Java, PHP, or C#—C is a relatively simple language to learn for anyone just starting to learn computer programming because of its limited number of keywords.
C is an imperative procedural language supporting structured programming, lexical variable scope, and recursion, with a static type system. It was designed to be compiled to provide low-level access to memory and language constructs that map efficiently to machine instructions, all with minimal runtime support.
Here is a good link on the CompilerServices namespace:
http://www.codeproject.com/KB/vb/DotNetCompilerArticle.aspx
You could use CSScript
http://www.csscript.net/
From their web site:
dynamic script = CSScript.LoadCode(@"using System;
public class Script
{
public void SayHello(string greeting)
{
Console.WriteLine(greeting);
}
}")
.CreateObject("*");
script.SayHello("Hello World!");
I think what you're looking for is LINQPad
. It'll let you run small bits of code without the overhead of making little one-off console apps to test things. Just for fun I wrote the following that'll compile and execute whatever is in the textbox.
void Main()
{
TextBox textBox = new TextBox()
{
Multiline = true,
Size = new Size(200, 60),
Text = @"string x = ""hello"";int myLength;myLength = x.Length;MessageBox.Show(myLength.ToString());"
};
Button button = new Button()
{
Location = new Point(0, 60)
};
button.Click += new EventHandler(delegate(object sender, EventArgs e)
{
var csc = new CSharpCodeProvider(new Dictionary<string, string>() { { "CompilerVersion", "v3.5" } });
var parameters = new CompilerParameters(new[] { "mscorlib.dll", "System.dll", "System.Windows.Forms.dll" }, "foo.exe", true);
parameters.GenerateExecutable = true;
CompilerResults results = csc.CompileAssemblyFromSource(parameters,
@"
using System.Windows.Forms;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
" +
textBox.Text
+ @"
}
}
}
");
Process proc = Process.Start("foo.exe");
}
);
Form f = new Form
{
Controls = { textBox, button }
};
Application.Run(f);
}
I actually wrote it in LINQPad
but it would be very easy to get running in Visual Studio
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With