CSharp - 带有Gotos的单声道CSharp编译器错误

  显示原文与译文双语对照的内容
0 0

我使用 Mono.CSharp.Evaluator的实例编译一些代码并返回函数。 在我使用goto之前,它一直没有问题。 我正在为. NET 4.5构建 VS2012. 在 evaluator 。evaluate中运行下面的代码,并将它的存储在一个对象中,以便以后执行:


 Func<Dictionary<string, object>, dynamic, LogWrapperMethod, LogWrapperMethod, LogWrapperMethod, LogWrapperMethod, ExcWrapperMethod, AddResultWrapperMethod, int> a = new Func<Dictionary<string, object>, dynamic, LogWrapperMethod, LogWrapperMethod, LogWrapperMethod, LogWrapperMethod, ExcWrapperMethod, AddResultWrapperMethod, int>((parameters, self, debug, log, warn, error, exception, addResult) =>
 {

 Console.WriteLine("beforegoto");
 goto Ben;
 Ben:
 Console.WriteLine("gotoResult");
 return 0;

 });

我得到 InternalErrorException ( ( 1,1 ): ) InnerException

ILGenerator中的错误标签内容


at System.Reflection.Emit.ILGenerator.GetLabelPos(Label lbl)
at System.Reflection.Emit.ILGenerator.BakeByteArray()
at System.Reflection.Emit.MethodBuilder.CreateMethodBodyHelper(ILGenerator il)
at System.Reflection.Emit.TypeBuilder.CreateTypeNoLock()
at System.Reflection.Emit.TypeBuilder.CreateType()
at Mono.CSharp.TypeDefinition.CloseContainer()

我正在设置评估程序( _e )


 _settings = new CompilerSettings
 {
 EnhancedWarnings = true,
 Stacktrace = true,
 ShowFullPaths = true,
 Timestamps = true,
 Optimize = true,
 AssemblyReferences = new List<string>
 {
"Microsoft.CSharp.dll"
 },
 };
 _ctx = new CompilerContext(_settings, new Reporter());
 _e = new Evaluator(_ctx);
 _e.Run("using System;");
 _e.Run("using System.Collections.Generic;");
 _e.Run("using System.Dynamic;");
 _e.Run("using System.Linq;");
 _e.Run("using System.Text.RegularExpressions;");

谁有什么想法来解决这个问题?

谢谢,本

时间: 原作者:

0 0

经过一些修改,我修改了这个问题,更改了 Evaluator.Run,的运行代码,然后运行 Evaluator.Evaluate 。 下面修改的代码


_e.Run("object o = Func<Dictionary<string, object>, dynamic, LogWrapperMethod, LogWrapperMethod, LogWrapperMethod, LogWrapperMethod, ExcWrapperMethod, AddResultWrapperMethod, int> a = new Func<Dictionary<string, object>, dynamic, LogWrapperMethod, LogWrapperMethod, LogWrapperMethod, LogWrapperMethod, ExcWrapperMethod, AddResultWrapperMethod, int>((parameters, self, debug, log, warn, error, exception, addResult) =>
 {

 Console.WriteLine("beforegoto");
 goto Ben;
 Ben:
 Console.WriteLine("gotoResult");
 return 0;

 });");
object func = _e.Evaluate("o");

原作者:
...