我想运行包含表单的 jscript.net 代码,一些带有事件的按钮。所有这些都必须在 c# 中通过反射完成,但我找不到这些事件的体面示例。请给我一些帮助。这是我到目前为止所拥有的,但最后一行会有错误
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());