我想運行jscript.net代碼包含一個窗體,一些按鈕與事件掛鉤。所有這些都必須在c#中用反射來完成,但我找不到那些事件的體面示例。請給我一些幫助。這是我到現在爲止,但如果你想在C#應用程序運行JavaScript,你最好使用js的詮釋者jscript.net代碼在C#反射
我用jint最後一行將錯誤
StringBuilder sb = new StringBuilder();
sb.AppendLine("import System.Windows.Forms;");
sb.AppendLine("class EventTestForm extends Form");
sb.AppendLine("{");
sb.AppendLine(" var btn : Button;");
sb.AppendLine("function EventTestForm()");
sb.AppendLine("{");
sb.AppendLine(" btn = new Button; btn.Text = \"Fire Event\"; Controls.Add(btn); btn.add_Click(ButtonEventHandler1);");
sb.AppendLine("}");
sb.AppendLine("function ButtonEventHandler1(sender, e : EventArgs)");
sb.AppendLine("{");
sb.AppendLine(" MessageBox.Show(\"Event is Fired!\");");
sb.AppendLine("}");
sb.AppendLine("}");
sb.AppendLine("MessageBox.Show(\"Hello world\");");
// Create the compiler object
JScriptCodeProvider provider = new JScriptCodeProvider();
ICodeCompiler compiler = provider.CreateCompiler();
CompilerParameters options = new CompilerParameters();
options.GenerateInMemory = true;
options.GenerateExecutable = true;
options.ReferencedAssemblies.Add("System.Windows.Forms");
CompilerResults results = compiler.CompileAssemblyFromSource(options, sb.ToString());
什麼是錯誤消息??? – Liam 2012-07-26 16:08:25
System.Reflection.Assembly._nLoad(AssemblyName fileName,String codeBase,Evidence assemblySecurity,Assembly locationHint,StackCrawlMark&stackMark,Boolean throwOnFileNotFound,Boolean forIntrospection) – 2012-07-26 16:18:58
那不是錯誤消息嗎?運行時是不是編譯或拋出異常? – Liam 2012-07-27 08:00:13