0

我尝试使用 Silverlight DLR 制作可编写脚本的应用程序。当我尝试执行包含两行或多行代码的 JScript 代码时,只执行第一行。例如:我在С# 上编写了已编译的 SL 应用程序。主页包含名为“lblMessage”的标签和带有 Click 事件处理程序的按钮。

private void Button_Click(object sender, RoutedEventArgs e)  
{  
  ScriptRuntime scriptRuntime = ScriptRuntime.Create();  
  foreach (string name in new string[] { "mscorlib", "System", "System.Windows", "System.Windows.Browser", "System.Net" })
  {
     scriptRuntime.LoadAssembly( scriptRuntime.Host.PlatformAdaptationLayer.LoadAssembly(name) );  
  }  
  ScriptEngine scriptEngine = scriptRuntime.GetEngine("js");  
  ScriptScope baseScope = scriptEngine.CreateScope();  
  gsFormManager fm = gsApplicationManager.FormManager;  
  baseScope.SetVariable("lblMessage", lblMessage);  
  string script = "lblMessage.Text = 'First line of code';\r\n" + "lblMessage.Text = 'Second line of code'";  
  ScriptSource scriptSource = scriptEngine.CreateScriptSourceFromString(script);  
  CompiledCode compiledCode = scriptSource.Compile();  
  compiledCode.Execute(baseScope);  
}

执行后 Label.Text 将等于“第一行代码”字符串。

为什么忽略第二行代码?

谢谢你。

4

1 回答 1

0

也许您还应该;在第二行末尾添加一个(分号)...?

于 2009-06-16T05:46:31.240 回答