샘플 소스
ScriptEngine

//
private void button1_Click(object sender, EventArgs e)
 {
 if (txtSource.Text == "")
 {
 MessageBox.Show("No script to process");
 return;
 }
 if (gridOutput.Rows.Count < 1)
 {
 MessageBox.Show("No X, Y values defined");
 return;
 }
 ScriptEngine Engine = null;
 if (btnCSharp.Checked)
 Engine = new ScriptEngine(ScriptEngine.Languages.CSharp);
 if (btnJScript.Checked)
 Engine = new ScriptEngine(ScriptEngine.Languages.JScript);
 if (btnVBasic.Checked)
 Engine = new ScriptEngine(ScriptEngine.Languages.VBasic);
 if (btnFSharp.Checked)
 Engine = new ScriptEngine(ScriptEngine.Languages.FSharp);
 if (Engine != null)
 {
 string code = "";
 foreach (string line in txtSource.Lines)
 {
 if (Engine.Language == ScriptEngine.Languages.FSharp)
 code += " " + line + "\r\n";
 else
 code += line + "\r\n";
 }
 Engine.Code = code;
 Engine.AddVariable("X");
 Engine.AddVariable("Y");
 if (Engine.Compile())
 {
 foreach (DataGridViewRow row in gridOutput.Rows)
 {
 if (row.Cells[0].Value != null)
 {
 Engine.SetVariable("X", Double.Parse(row.Cells[0].Value.ToString()));
 Engine.SetVariable("Y", Double.Parse(row.Cells[1].Value.ToString()));
 double result = Engine.Evaluate();
 row.Cells[2].Value = result;
 }
 }
 }
 else
 {
 MessageBox.Show("Compiler message: " + Engine.Messages[0]);
 }
 Engine.Unload();
 Engine = null;
 }
 else
 {
 MessageBox.Show("Unable to allocate scripting engine");
 return;
 }
 }
//
298 Comments
댓글 남기기