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


C# AssemblyCompiler.Compile方法代码示例

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


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

示例1: Generate

		private Assembly Generate()
		{
			var assemblyPath = Path.GetDirectoryName(this.assembly.Location);
			var trees = new ConcurrentBag<SyntaxTree>();
			var allowUnsafe = false;

         Parallel.ForEach(assembly.GetExportedTypes()
				.Where(_ => string.IsNullOrWhiteSpace(_.Validate(this.options.Serialization, new AssemblyNameGenerator(_))) && !typeof(Array).IsAssignableFrom(_) &&
					!typeof(Enum).IsAssignableFrom(_) && !typeof(ValueType).IsAssignableFrom(_) && 
					!typeof(Delegate).IsAssignableFrom(_)), _ =>
				{
					var builder = new AssemblyBuilder(_, 
						new ReadOnlyDictionary<int, ReadOnlyCollection<HandlerInformation>>(
							new Dictionary<int, ReadOnlyCollection<HandlerInformation>>()), 
						new SortedSet<string>(), this.options);
					builder.Build();
					trees.Add(builder.Tree);
					allowUnsafe |= builder.IsUnsafe;
            });

			var referencedAssemblies = this.assembly.GetReferencedAssemblies().Select(_ => Assembly.Load(_)).ToList();
			referencedAssemblies.Add(this.assembly);

         var compiler = new AssemblyCompiler(trees, this.options.Optimization, 
				new AssemblyNameGenerator(this.assembly).AssemblyName, 
				referencedAssemblies.AsReadOnly(), currentDirectory, allowUnsafe, this.options.AllowWarnings);
			compiler.Compile();
			return compiler.Result;
      }
开发者ID:JamesBender,项目名称:Rocks,代码行数:29,代码来源:RockAssembly.cs

示例2: DecompileMethod

        public override void DecompileMethod(Mono.Cecil.MethodDefinition method, ICSharpCode.Decompiler.ITextOutput output, DecompilationOptions options)
        {
            var declaringType = method.DeclaringType;
            var assembly = declaringType.Module.Assembly;

            if ((compiler == null) || (compiler.Assembly != assembly))
            {
                compiler = null;
                var c = new AssemblyCompiler(assembly, new NamespaceConverter("pkg.name", ""));
                c.Compile();
                compiler = c;
            }

            var cmethod = compiler.GetMethod(method);
            if ((cmethod != null) && (cmethod.RLBody != null))
            {
                var body = cmethod.RLBody;
                var basicBlocks = BasicBlock.Find(body);

                foreach (var block in basicBlocks)
                {
                    output.Write(string.Format("D_{0:X4}:", block.Entry.Index));
                    output.WriteLine();
                    output.Indent();
                    foreach (var ins in block.Instructions)
                    {
                        output.Write(ins.ToString());
                        output.WriteLine();
                    }
                    output.Unindent();                    
                }

                if (body.Exceptions.Any())
                {
                    output.WriteLine();
                    output.Write("Exception handlers:");
                    output.WriteLine();
                    output.Indent();
                    foreach (var handler in body.Exceptions)
                    {
                        output.Write(string.Format("{0:x4}-{1:x4}", handler.TryStart.Index, handler.TryEnd.Index));
                        output.WriteLine();
                        output.Indent();
                        foreach (var c in handler.Catches)
                        {
                            output.Write(string.Format("{0} => {1:x4}", c.Type, c.Instruction.Index));                            
                            output.WriteLine();
                        }
                        if (handler.CatchAll != null)
                        {
                            output.Write(string.Format("{0} => {1:x4}", "<any>", handler.CatchAll.Index));
                            output.WriteLine();                            
                        }
                        output.Unindent();
                    }
                    output.Unindent();
                }
            }
            else
            {
                output.Write("Method not found in dex");
                output.WriteLine();
            }
        }
开发者ID:rfcclub,项目名称:dot42,代码行数:64,代码来源:RLLanguage.cs


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