當前位置: 首頁>>代碼示例>>C#>>正文


C# Class.PrepareEmit方法代碼示例

本文整理匯總了C#中Mono.CSharp.Class.PrepareEmit方法的典型用法代碼示例。如果您正苦於以下問題:C# Class.PrepareEmit方法的具體用法?C# Class.PrepareEmit怎麽用?C# Class.PrepareEmit使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Mono.CSharp.Class的用法示例。


在下文中一共展示了Class.PrepareEmit方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: CompileBlock

		CompiledMethod CompileBlock (Class host, Undo undo, Report Report)
		{
#if STATIC
			throw new NotSupportedException ();
#else
			string current_debug_name = "eval-" + count + ".dll";
			++count;

			AssemblyDefinitionDynamic assembly;
			AssemblyBuilderAccess access;

			if (Environment.GetEnvironmentVariable ("SAVE") != null) {
				access = AssemblyBuilderAccess.RunAndSave;
				assembly = new AssemblyDefinitionDynamic (module, current_debug_name, current_debug_name);
				assembly.Importer = importer;
			} else {
#if NET_4_0
				access = AssemblyBuilderAccess.RunAndCollect;
#else
				access = AssemblyBuilderAccess.Run;
#endif
				assembly = new AssemblyDefinitionDynamic (module, current_debug_name);
			}

			assembly.Create (AppDomain.CurrentDomain, access);

			Method expression_method;
			if (host != null) {
				var base_class_imported = importer.ImportType (base_class);
				var baseclass_list = new List<FullNamedExpression> (1) {
					new TypeExpression (base_class_imported, host.Location)
				};

				host.SetBaseTypes (baseclass_list);

				expression_method = (Method) host.Members[0];

				if ((expression_method.ModFlags & Modifiers.ASYNC) != 0) {
					//
					// Host method is async. When WaitOnTask is set we wrap it with wait
					//
					// void AsyncWait (ref object $retval) {
					//	$retval = Host();
					//	((Task)$retval).Wait();  // When WaitOnTask is set
					// }
					//
					var p = new ParametersCompiled (
						new Parameter (new TypeExpression (module.Compiler.BuiltinTypes.Object, Location.Null), "$retval", Parameter.Modifier.REF, null, Location.Null)
					);

					var method = new Method(host, new TypeExpression(module.Compiler.BuiltinTypes.Void, Location.Null),
						Modifiers.PUBLIC | Modifiers.STATIC, new MemberName("AsyncWait"), p, null);

					method.Block = new ToplevelBlock(method.Compiler, p, Location.Null);
					method.Block.AddStatement(new StatementExpression (new SimpleAssign(
						new SimpleName(p [0].Name, Location.Null),
						new Invocation(new SimpleName(expression_method.MemberName.Name, Location.Null), new Arguments(0)),
						Location.Null), Location.Null));

					if (WaitOnTask) {
						var task = new Cast (expression_method.TypeExpression, new SimpleName (p [0].Name, Location.Null), Location.Null);

						method.Block.AddStatement (new StatementExpression (new Invocation (
								new MemberAccess (task, "Wait", Location.Null),
							new Arguments (0)), Location.Null));
					}

					host.AddMember(method);

					expression_method = method;
				}

				host.CreateContainer();
				host.DefineContainer();
				host.Define();

			} else {
				expression_method = null;
			}

			module.CreateContainer ();

			// Disable module and source file re-definition checks
			module.EnableRedefinition ();
			source_file.EnableRedefinition ();

			module.Define ();

			if (Report.Errors != 0){
				if (undo != null)
					undo.ExecuteUndo ();

				return null;
			}

			if (host != null){
				host.PrepareEmit ();
				host.EmitContainer ();
			}
			
//.........這裏部分代碼省略.........
開發者ID:FrancisVarga,項目名稱:mono,代碼行數:101,代碼來源:eval.cs

示例2: CompileBlock

        CompiledMethod CompileBlock(Class host, Undo undo, Report Report)
        {
            #if STATIC
            throw new NotSupportedException ();
            #else
            string current_debug_name = "eval-" + count + ".dll";
            ++count;

            AssemblyDefinitionDynamic assembly;
            AssemblyBuilderAccess access;

            if (Environment.GetEnvironmentVariable ("SAVE") != null) {
                access = AssemblyBuilderAccess.RunAndSave;
                assembly = new AssemblyDefinitionDynamic (module, current_debug_name, current_debug_name);
                assembly.Importer = importer;
            } else {
            #if NET_4_0
                access = AssemblyBuilderAccess.RunAndCollect;
            #else
                access = AssemblyBuilderAccess.Run;
            #endif
                assembly = new AssemblyDefinitionDynamic (module, current_debug_name);
            }

            assembly.Create (AppDomain.CurrentDomain, access);

            Method expression_method;
            if (host != null) {
                var base_class_imported = importer.ImportType (base_class);
                var baseclass_list = new List<FullNamedExpression> (1) {
                    new TypeExpression (base_class_imported, host.Location)
                };

                host.SetBaseTypes (baseclass_list);

                host.CreateContainer ();
                host.DefineContainer ();
                host.Define ();

                expression_method = (Method) host.Members[0];
            } else {
                expression_method = null;
            }

            module.CreateContainer ();

            // Disable module and source file re-definition checks
            module.EnableRedefinition ();
            source_file.EnableRedefinition ();

            module.Define ();

            if (Report.Errors != 0){
                if (undo != null)
                    undo.ExecuteUndo ();

                return null;
            }

            if (host != null){
                host.PrepareEmit ();
                host.EmitContainer ();
            }

            module.EmitContainer ();
            if (Report.Errors != 0){
                if (undo != null)
                    undo.ExecuteUndo ();
                return null;
            }

            module.CloseContainer ();
            if (host != null)
                host.CloseContainer ();

            if (access == AssemblyBuilderAccess.RunAndSave)
                assembly.Save ();

            if (host == null)
                return null;

            //
            // Unlike Mono, .NET requires that the MethodInfo is fetched, it cant
            // work from MethodBuilders.   Retarded, I know.
            //
            var tt = assembly.Builder.GetType (host.TypeBuilder.Name);
            var mi = tt.GetMethod (expression_method.MemberName.Name);

            //
            // We need to then go from FieldBuilder to FieldInfo
            // or reflection gets confused (it basically gets confused, and variables override each
            // other).
            //
            foreach (var member in host.Members) {
                var field = member as Field;
                if (field == null)
                    continue;

                var fi = tt.GetField (field.Name);

//.........這裏部分代碼省略.........
開發者ID:segaman,項目名稱:NRefactory,代碼行數:101,代碼來源:eval.cs


注:本文中的Mono.CSharp.Class.PrepareEmit方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。