当前位置: 首页>>代码示例>>C#>>正文


C# AssemblyDefinitionDynamic.Create方法代码示例

本文整理汇总了C#中AssemblyDefinitionDynamic.Create方法的典型用法代码示例。如果您正苦于以下问题:C# AssemblyDefinitionDynamic.Create方法的具体用法?C# AssemblyDefinitionDynamic.Create怎么用?C# AssemblyDefinitionDynamic.Create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AssemblyDefinitionDynamic的用法示例。


在下文中一共展示了AssemblyDefinitionDynamic.Create方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetCompletions

		public string [] GetCompletions (string input, out string prefix)
		{
			prefix = "";
			if (input == null || input.Length == 0)
				return null;
			
			lock (evaluator_lock){
				if (!inited)
					Init ();
				
				bool partial_input;
				CSharpParser parser = ParseString (ParseMode.GetCompletions, input, out partial_input);
				if (parser == null){
					return null;
				}
				
				Class parser_result = parser.InteractiveResult;

#if NET_4_0
				var access = AssemblyBuilderAccess.RunAndCollect;
#else
				var access = AssemblyBuilderAccess.Run;
#endif
				var a = new AssemblyDefinitionDynamic (module, "completions");
				a.Create (AppDomain.CurrentDomain, access);
				module.SetDeclaringAssembly (a);

				// Need to setup MemberCache
				parser_result.CreateContainer ();

				var method = parser_result.Members[0] as Method;
				BlockContext bc = new BlockContext (method, method.Block, ctx.BuiltinTypes.Void);

				try {
					method.Block.Resolve (null, bc, method);
				} catch (CompletionResult cr) {
					prefix = cr.BaseText;
					return cr.Result;
				} 
			}
			return null;
		}
开发者ID:KAW0,项目名称:Alter-Native,代码行数:42,代码来源:eval.cs

示例2: GetCompletions

		public static string [] GetCompletions (string input, out string prefix)
		{
			prefix = "";
			if (input == null || input.Length == 0)
				return null;
			
			lock (evaluator_lock){
				if (!inited)
					Init ();
				
				bool partial_input;
				CSharpParser parser = ParseString (ParseMode.GetCompletions, input, out partial_input);
				if (parser == null){
					if (CSharpParser.yacc_verbose_flag != 0)
						Console.WriteLine ("DEBUG: No completions available");
					return null;
				}
				
				Class parser_result = parser.InteractiveResult;

				try {
					var a = new AssemblyDefinitionDynamic (RootContext.ToplevelTypes, "temp");
					a.Create (AppDomain.CurrentDomain, AssemblyBuilderAccess.Run);
					RootContext.ToplevelTypes.SetDeclaringAssembly (a);
					RootContext.ToplevelTypes.CreateType ();
					RootContext.ToplevelTypes.Define ();

					parser_result.CreateType ();
					parser_result.Define ();
					if (ctx.Report.Errors != 0)
						return null;
					
					MethodOrOperator method = null;
					foreach (MemberCore member in parser_result.Methods){
						if (member.Name != "Host")
							continue;
						
						method = (MethodOrOperator) member;
						break;
					}
					if (method == null)
						throw new InternalErrorException ("did not find the the Host method");

					BlockContext bc = new BlockContext (method, method.Block, method.ReturnType);

					try {
						method.Block.Resolve (null, bc, method);
					} catch (CompletionResult cr){
						prefix = cr.BaseText;
						return cr.Result;
					} 
				} finally {
					parser.undo.ExecuteUndo ();
				}
				
			}
			return null;
		}
开发者ID:keith512,项目名称:mono,代码行数:58,代码来源:eval.cs

示例3: Compile


//.........这里部分代码省略.........
            if (settings.TokenizeOnly || settings.ParseOnly)
                return true;

            if (RootContext.ToplevelTypes.NamespaceEntry != null)
                throw new InternalErrorException ("who set it?");

            var output_file = settings.OutputFile;
            string output_file_name;
            if (output_file == null) {
                output_file_name = Location.FirstFile;

                if (output_file_name == null) {
                    Report.Error (1562, "If no source files are specified you must specify the output file with -out:");
                    return false;
                }

                int pos = output_file_name.LastIndexOf ('.');

                if (pos > 0)
                    output_file_name = output_file_name.Substring (0, pos);

                output_file_name += settings.TargetExt;
                output_file = output_file_name;
            } else {
                output_file_name = Path.GetFileName (output_file);
            }

            #if STATIC
            var importer = new StaticImporter (module);
            var references_loader = new StaticLoader (importer, ctx);

            tr.Start (TimeReporter.TimerType.AssemblyBuilderSetup);
            var assembly = new AssemblyDefinitionStatic (module, references_loader, output_file_name, output_file);
            assembly.Create (references_loader.Domain);
            tr.Stop (TimeReporter.TimerType.AssemblyBuilderSetup);

            // Create compiler types first even before any referenced
            // assembly is loaded to allow forward referenced types from
            // loaded assembly into compiled builder to be resolved
            // correctly
            tr.Start (TimeReporter.TimerType.CreateTypeTotal);
            module.CreateType ();
            importer.AddCompiledAssembly (assembly);
            tr.Stop (TimeReporter.TimerType.CreateTypeTotal);

            references_loader.LoadReferences (module);

            tr.Start (TimeReporter.TimerType.PredefinedTypesInit);
            if (!ctx.BuildinTypes.CheckDefinitions (module))
                return false;

            tr.Stop (TimeReporter.TimerType.PredefinedTypesInit);

            references_loader.LoadModules (assembly, module.GlobalRootNamespace);
            #else
            var assembly = new AssemblyDefinitionDynamic (module, output_file_name, output_file);
            module.SetDeclaringAssembly (assembly);

            var importer = new ReflectionImporter (module, ctx.BuildinTypes);
            assembly.Importer = importer;

            var loader = new DynamicLoader (importer, ctx);
            loader.LoadReferences (module);

            if (!ctx.BuildinTypes.CheckDefinitions (module))
                return false;
开发者ID:RainsSoft,项目名称:MonoCompilerAsAService,代码行数:67,代码来源:driver.cs

示例4: Compile

		//
		// Main compilation method
		//
		public bool Compile ()
		{
			var module = new ModuleContainer (ctx);
			RootContext.ToplevelTypes = module;

			if (timestamps) {
				stopwatch = Stopwatch.StartNew ();
				first_time = DateTime.Now;
			}

			Parse (module);
			ShowTime ("Parsing source files");

			if (Report.Errors > 0)
				return false;

			if (RootContext.TokenizeOnly || RootContext.ParseOnly)
				return true;

			if (RootContext.ToplevelTypes.NamespaceEntry != null)
				throw new InternalErrorException ("who set it?");

			//
			// Quick hack
			//
			var output_file = RootContext.OutputFile;
			string output_file_name;
			if (output_file == null) {
				if (first_source == null) {
					Report.Error (1562, "If no source files are specified you must specify the output file with -out:");
					return false;
				}

				int pos = first_source.LastIndexOf ('.');

				if (pos > 0)
					output_file = first_source.Substring (0, pos) + RootContext.TargetExt;
				else
					output_file = first_source + RootContext.TargetExt;

				output_file_name = output_file;
			} else {
				output_file_name = Path.GetFileName (output_file);
			}

			//
			// Load assemblies required
			//
			if (timestamps)
				stopwatch = Stopwatch.StartNew ();

#if STATIC
			var assembly = new AssemblyDefinitionStatic (module, output_file_name, output_file);
			module.SetDeclaringAssembly (assembly);

			var importer = new StaticImporter ();
			assembly.Importer = importer;

			var loader = new StaticLoader (importer, ctx);
			loader.LoadReferences (module);

			ShowTime ("Imporing referenced assemblies");

			if (!ctx.BuildinTypes.CheckDefinitions (module))
				return false;

			ShowTime ("Initializing predefined types");

			if (!assembly.Create (loader))
				return false;

			// System.Object was not loaded, use compiled assembly as corlib
			if (loader.Corlib == null)
				loader.Corlib = assembly.Builder;

			loader.LoadModules (assembly, module.GlobalRootNamespace);
#else
			var assembly = new AssemblyDefinitionDynamic (module, output_file_name, output_file);
			module.SetDeclaringAssembly (assembly);

			var importer = new ReflectionImporter (ctx.BuildinTypes);
			assembly.Importer = importer;

			var loader = new DynamicLoader (importer, ctx);
			loader.LoadReferences (module);

			ShowTime ("Imporing referenced assemblies");

			if (!ctx.BuildinTypes.CheckDefinitions (module))
				return false;

			ShowTime ("Initializing predefined types");

			if (!assembly.Create (AppDomain.CurrentDomain, AssemblyBuilderAccess.Save))
				return false;

			loader.LoadModules (assembly, module.GlobalRootNamespace);
//.........这里部分代码省略.........
开发者ID:litoMalone,项目名称:mono,代码行数:101,代码来源:driver.cs

示例5: CompileBlock

        CompiledMethod CompileBlock(Class host, Undo undo, Report Report)
        {
            string current_debug_name = "eval-" + count + ".dll";
            ++count;
            #if STATIC
            throw new NotSupportedException ();
            #else
            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.Run;
            #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.AddBasesForPart (host, baseclass_list);

                host.CreateType ();
                host.DefineType ();
                host.Define ();

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

            module.CreateType ();
            module.Define ();

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

                return null;
            }

            if (host != null){
                host.EmitType ();
            }

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

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

            //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.Name);

            if (host.Fields != null) {
                //
                // We need to then go from FieldBuilder to FieldInfo
                // or reflection gets confused (it basically gets confused, and variables override each
                // other).
                //
                foreach (Field field in host.Fields) {
                    var fi = tt.GetField (field.Name);

                    Tuple<FieldSpec, FieldInfo> old;

                    // If a previous value was set, nullify it, so that we do
                    // not leak memory
                    if (fields.TryGetValue (field.Name, out old)) {
                        if (old.Item1.MemberType.IsStruct) {
                            //
                            // TODO: Clear fields for structs
                            //
                        } else {
//.........这里部分代码省略.........
开发者ID:jorik041,项目名称:runcs,代码行数:101,代码来源:eval.cs

示例6: GetCompletions

        public string[] GetCompletions(string input, out string prefix)
        {
            prefix = "";
            if (input == null || input.Length == 0)
                return null;

            try
            {
                invoke_thread = System.Threading.Thread.CurrentThread;
                invoking = true;

                lock (evaluator_lock)
                {
                    if (!inited)
                        Init();

                    bool partial_input;
                    CSharpParser parser = ParseString(ParseMode.GetCompletions, input, out partial_input);
                    if (parser == null)
                    {
                        if (CSharpParser.yacc_verbose_flag != 0)
                            Console.WriteLine("DEBUG: No completions available");
                        return null;
                    }

                    Class parser_result = parser.InteractiveResult;

            #if NET_4_0
                var access = AssemblyBuilderAccess.Run;
            #else
                    var access = AssemblyBuilderAccess.Run;
            #endif
                    var a = new AssemblyDefinitionDynamic(module, "completions");
                    a.Create(AppDomain.CurrentDomain, access);
                    module.SetDeclaringAssembly(a);

                    // Need to setup MemberCache
                    parser_result.CreateType();

                    var method = parser_result.Methods[0] as Method;
                    BlockContext bc = new BlockContext(method, method.Block, TypeManager.void_type);

                    try
                    {
                        method.Block.Resolve(null, bc, method);
                    }
                    catch (CompletionResult cr)
                    {
                        prefix = cr.BaseText;
                        return cr.Result;
                    }
                }
            }
            catch (ThreadAbortException e)
            {
                Console.WriteLine("Interrupted!\n{0}", e);
            }
            finally
            {
                invoking = false;
            }

            return null;
        }
开发者ID:jorik041,项目名称:runcs,代码行数:64,代码来源:eval.cs

示例7: GetCompletions

		public string [] GetCompletions (string input, out string prefix)
		{
			prefix = "";
			if (input == null || input.Length == 0)
				return null;
			
			lock (evaluator_lock){
				if (!inited)
					Init ();
				
				bool partial_input;
				CSharpParser parser = ParseString (ParseMode.GetCompletions, input, out partial_input);
				if (parser == null){
					return null;
				}

				Class host = parser.InteractiveResult;

				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);

				var access = AssemblyBuilderAccess.RunAndCollect;
				var a = new AssemblyDefinitionDynamic (module, "completions");
				a.Create (AppDomain.CurrentDomain, access);
				module.SetDeclaringAssembly (a);

				// Need to setup MemberCache
				host.CreateContainer ();
				// Need to setup base type
				host.DefineContainer ();

				var method = host.Members[0] as Method;
				BlockContext bc = new BlockContext (method, method.Block, ctx.BuiltinTypes.Void);

				try {
					method.Block.Resolve (bc, method);
				} catch (CompletionResult cr) {
					prefix = cr.BaseText;
					return cr.Result;
				} 
			}
			return null;
		}
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:46,代码来源:eval.cs


注:本文中的AssemblyDefinitionDynamic.Create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。