Windows applicatipn中的Java脚本问题 [英] java script in windows applicatipn problem
本文介绍了Windows applicatipn中的Java脚本问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Windows应用程序中使用了Java脚本.但我在
遇到错误
i used java script in windows application. but i got error at
this.result = provider.CompileAssemblyFromSource
i.e Object reference not set to an instance of an object
怎么做?
how to do it?
CodeDomProvider provider;
CompilerParameters para;
CompilerResults result;
Assembly assembly;
Type jsType;
object jsObject;
public string Message;
public void ShowMessage()
{
MessageBox.Show(this.Message);
}
private void button1_Click_1(object sender, EventArgs e)
{
this.para = new CompilerParameters();
this.para.GenerateInMemory = true;
string text =
@"class JSSample
{
var obj;
function Main()
{
obj.Message = 'Hello world!';
obj.ShowMessage();
}
}";
this.result = provider.CompileAssemblyFromSource(this.para, text); // I got error here
this.assembly = result.CompiledAssembly;
this.jsType = assembly.GetType("JSSample");
this.jsObject = Activator.CreateInstance(this.jsType);
this.jsType.InvokeMember(
"obj",
BindingFlags.SetField,
null,
this.jsObject,
new object[] { this });
this.jsType.InvokeMember(
"Main",
BindingFlags.InvokeMethod,
null,
this.jsObject,
null);
}
}
推荐答案
CodeDomProvider
旨在用于已编译的jscript
文件,因为它不是被编译为的"javascript".并使用CLR.
如果要在应用程序中使用JavaScript引擎,请尝试使用以下一种方法:
http://jint.codeplex.com/ [ ^ ]
http://javascript.codeplex.com/ [ ^ ]
http://jurassic.codeplex.com/ [ ^ ]
TheCodeDomProvider
is meant to be used for compiledjscript
files, this is not "javascript" as it is compiled to .net and uses the CLR.
If you want a javascript engine within your application try using one of the following:
http://jint.codeplex.com/[^]
http://javascript.codeplex.com/[^]
http://jurassic.codeplex.com/[^]
这篇关于Windows applicatipn中的Java脚本问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文