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


C# AstBuilder.RunTransformations方法代码示例

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


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

示例1: GetMethodCode

        /// <summary>
        /// Returns the code for a specific algorithm.
        /// </summary>
        /// <returns>The algorithm code.</returns>
        /// <param name="algorithmType">Algorithm type.</param>
        public static MethodDeclaration GetMethodCode(Type algorithmType, out AstBuilder astBuilder, string methodName)
        {
            var resolver = new DefaultAssemblyResolver();
            resolver.AddSearchDirectory(new FileInfo(Assembly.GetExecutingAssembly().Location).Directory.FullName);
            var parameters = new ReaderParameters
            {
                AssemblyResolver = resolver,
            };

            // Load Tychaia.ProceduralGeneration into Mono.Cecil.
            var module = AssemblyDefinition.ReadAssembly(
                Assembly.GetExecutingAssembly().Location,
                parameters).MainModule;

            // Now we have a reference to the method we want to decompile.
            TypeDefinition cecilType;
            MethodDefinition processCell;
            FindMethodName(module, algorithmType, methodName, out processCell, out cecilType);
            var decompilerSettings = new DecompilerSettings();
            astBuilder =
                new AstBuilder(new DecompilerContext(module) { CurrentType = cecilType, Settings = decompilerSettings });
            astBuilder.AddMethod(processCell);
            try
            {
                astBuilder.RunTransformations();
            }
            catch (AssemblyResolutionException ex)
            {
                throw new Exception(
                    "Unable to decompile algorithm source code for " + algorithmType.FullName + ".",
                    ex);
            }

            astBuilder.CompilationUnit.AcceptVisitor(new InsertParenthesesVisitor
            {
                InsertParenthesesForReadability = true
            });

            // Return.
            return
                astBuilder.CompilationUnit.Members.Where(v => v is MethodDeclaration).Cast<MethodDeclaration>().First();
        }
开发者ID:TreeSeed,项目名称:Tychaia,代码行数:47,代码来源:DecompileUtil.cs

示例2: Create

		public static ILSpyUnresolvedFile Create(DecompiledTypeReference name, AstBuilder builder)
		{
			var writer = new StringWriter();
			var target = new TextWriterTokenWriter(writer) { IndentationString = "\t" };
			var output = new DebugInfoTokenWriterDecorator(TokenWriter.WrapInWriterThatSetsLocationsInAST(target));
			builder.RunTransformations();
			var syntaxTree = builder.SyntaxTree;
			
			syntaxTree.AcceptVisitor(new InsertParenthesesVisitor { InsertParenthesesForReadability = true });
			syntaxTree.AcceptVisitor(new CSharpOutputVisitor(output, FormattingOptionsFactory.CreateSharpDevelop()));
			ILSpyUnresolvedFile file = new ILSpyUnresolvedFile(name);
			var v = new TypeSystemConvertVisitor(file);
			syntaxTree.AcceptVisitor(v);
	
			file.MemberLocations = output.MemberLocations;
			file.DebugSymbols = output.DebugSymbols;
			file.output = writer.ToString();
			
			return file;
		}
开发者ID:2594636985,项目名称:SharpDevelop,代码行数:20,代码来源:ILSpyUnresolvedFile.cs

示例3: DecompileMethod

		// There are several methods available to override; in this sample, we deal with methods only
		
		public override void DecompileMethod(MethodDefinition method, ITextOutput output, DecompilationOptions options)
		{
			if (method.Body != null) {
				output.WriteLine("Size of method: {0} bytes", method.Body.CodeSize);
				
				ISmartTextOutput smartOutput = output as ISmartTextOutput;
				if (smartOutput != null) {
					// when writing to the text view (but not when writing to a file), we can even add UI elements such as buttons:
					smartOutput.AddButton(null, "Click me!", (sender, e) => (sender as Button).Content = "I was clicked!");
					smartOutput.WriteLine();
				}
				
				// ICSharpCode.Decompiler.Ast.AstBuilder can be used to decompile to C#
				AstBuilder b = new AstBuilder(new DecompilerContext(method.Module) {
				                              	Settings = options.DecompilerSettings,
				                              	CurrentType = method.DeclaringType
				                              });
				b.AddMethod(method);
				b.RunTransformations();
				output.WriteLine("Decompiled AST has {0} nodes", b.CompilationUnit.DescendantsAndSelf.Count());
			}
		}
开发者ID:95ulisse,项目名称:ILEdit,代码行数:24,代码来源:CustomLanguage.cs

示例4: GetTooltip

		public override string GetTooltip(MemberReference member)
		{
			MethodDefinition md = member as MethodDefinition;
			PropertyDefinition pd = member as PropertyDefinition;
			EventDefinition ed = member as EventDefinition;
			FieldDefinition fd = member as FieldDefinition;
			if (md != null || pd != null || ed != null || fd != null) {
				AstBuilder b = new AstBuilder(new DecompilerContext(member.Module) { Settings = new DecompilerSettings { UsingDeclarations = false } });
				b.DecompileMethodBodies = false;
				if (md != null)
					b.AddMethod(md);
				else if (pd != null)
					b.AddProperty(pd);
				else if (ed != null)
					b.AddEvent(ed);
				else
					b.AddField(fd);
				b.RunTransformations();
				foreach (var attribute in b.CompilationUnit.Descendants.OfType<AttributeSection>())
					attribute.Remove();

				StringWriter w = new StringWriter();
				b.GenerateCode(new PlainTextOutput(w));
				return Regex.Replace(w.ToString(), @"\s+", " ").TrimEnd();
			}

			return base.GetTooltip(member);
		}
开发者ID:Netring,项目名称:ILSpy,代码行数:28,代码来源:CSharpLanguage.cs

示例5: RunTransformsAndGenerateCode

		void RunTransformsAndGenerateCode(AstBuilder astBuilder, ITextOutput output, DecompilationOptions options, IAstTransform additionalTransform = null)
		{
			astBuilder.RunTransformations(transformAbortCondition);
			if (additionalTransform != null) {
				additionalTransform.Run(astBuilder.CompilationUnit);
			}
			if (options.DecompilerSettings.ShowXmlDocumentation) {
				AddXmlDocTransform.Run(astBuilder.CompilationUnit);
			}
			astBuilder.GenerateCode(output);
		}
开发者ID:Netring,项目名称:ILSpy,代码行数:11,代码来源:CSharpLanguage.cs

示例6: RunTransformsAndGenerateCode

 void RunTransformsAndGenerateCode(AstBuilder astBuilder, ITextOutput output, DecompilationOptions options, IAstTransform additionalTransform = null)
 {
     astBuilder.RunTransformations(transformAbortCondition);
     if (additionalTransform != null) {
         additionalTransform.Run(astBuilder.SyntaxTree);
     }
     if (options.DecompilerSettings.ShowXmlDocumentation) {
         try {
             AddXmlDocTransform.Run(astBuilder.SyntaxTree);
         } catch (XmlException ex) {
             string[] msg = (" Exception while reading XmlDoc: " + ex.ToString()).Split(new[]{'\r', '\n'}, StringSplitOptions.RemoveEmptyEntries);
             var insertionPoint = astBuilder.SyntaxTree.FirstChild;
             for (int i = 0; i < msg.Length; i++)
                 astBuilder.SyntaxTree.InsertChildBefore(insertionPoint, new Comment(msg[i], CommentType.Documentation), Roles.Comment);
         }
     }
     astBuilder.GenerateCode(output);
 }
开发者ID:PoroCYon,项目名称:ILSpy,代码行数:18,代码来源:CSharpLanguage.cs

示例7: Run

        void Run(Config config)
        {
            if (config.ShowHelp) {
                Console.WriteLine ("Netjs compiler, Copyright 2014 Frank A. Krueger");
                Console.WriteLine ("netjs [options] assembly-file");
                return;
            }

            if (string.IsNullOrEmpty (config.MainAssembly)) {
                throw new Exception ("No assembly specified.");
            }

            var asmPath = Path.GetFullPath (config.MainAssembly);
            asmDir = Path.GetDirectoryName (asmPath);
            var outPath = Path.ChangeExtension (asmPath, ".ts");

            Step ("Reading IL");
            var parameters = new ReaderParameters {
                AssemblyResolver = this,
            };
            var asm = AssemblyDefinition.ReadAssembly (asmPath, parameters);
            mscorlib = AssemblyDefinition.ReadAssembly (typeof(String).Assembly.Location, parameters);
            system = AssemblyDefinition.ReadAssembly (typeof(INotifyPropertyChanged).Assembly.Location, parameters);
            systemCore = AssemblyDefinition.ReadAssembly (typeof(Enumerable).Assembly.Location, parameters);

            Step ("Decompiling IL to C#");
            var context = new DecompilerContext (asm.MainModule);
            context.Settings.ForEachStatement = false;
            context.Settings.ObjectOrCollectionInitializers = false;
            context.Settings.UsingStatement = false;
            context.Settings.AsyncAwait = false;
            context.Settings.AutomaticProperties = true;
            context.Settings.AutomaticEvents = true;
            context.Settings.QueryExpressions = false;
            context.Settings.AlwaysGenerateExceptionVariableForCatchBlocks = true;
            context.Settings.UsingDeclarations = false;
            context.Settings.FullyQualifyAmbiguousTypeNames = true;
            context.Settings.YieldReturn = false;
            var builder = new AstBuilder (context);
            builder.AddAssembly (asm);
            foreach (var a in referencedAssemblies.Values) {
                if (a != null)
                    builder.AddAssembly (a);
            }
            builder.RunTransformations ();

            Step ("Translating C# to TypeScript");
            new CsToTs ().Run (builder.SyntaxTree);

            Step ("Writing");
            using (var outputWriter = new StreamWriter (outPath)) {
                var output = new PlainTextOutput (outputWriter);
                builder.GenerateCode (output, (s, e) => new TsOutputVisitor (s, e));
            }

            Step ("Done");
        }
开发者ID:ninenine,项目名称:Netjs,代码行数:57,代码来源:App.cs

示例8: RunTransformsAndGenerateCode

		void RunTransformsAndGenerateCode(AstBuilder astBuilder, ITextOutput output, DecompilationOptions options, ModuleDefinition module)
		{
			astBuilder.RunTransformations(transformAbortCondition);
			if (options.DecompilerSettings.ShowXmlDocumentation)
				AddXmlDocTransform.Run(astBuilder.CompilationUnit);
			var unit = astBuilder.CompilationUnit.AcceptVisitor(new CSharpToVBConverterVisitor(new ILSpyEnvironmentProvider()), null);
			var outputFormatter = new VBTextOutputFormatter(output);
			var formattingPolicy = new VBFormattingOptions();
			unit.AcceptVisitor(new OutputVisitor(outputFormatter, formattingPolicy), null);
		}
开发者ID:Netring,项目名称:ILSpy,代码行数:10,代码来源:VBLanguage.cs

示例9: RunTransformsAndGenerateCode

 void RunTransformsAndGenerateCode(AstBuilder astBuilder, ITextOutput output, DecompilationContext ctx, IAstTransform additionalTransform = null)
 {
     astBuilder.RunTransformations(transformAbortCondition);
     if (additionalTransform != null) {
         additionalTransform.Run(astBuilder.SyntaxTree);
     }
     AddXmlDocumentation(langSettings.Settings, astBuilder);
     astBuilder.GenerateCode(output);
 }
开发者ID:kulminati,项目名称:dnSpy,代码行数:9,代码来源:CSharpLanguage.cs

示例10: RunTransformsAndGenerateCode

		void RunTransformsAndGenerateCode(AstBuilder astBuilder, ITextOutput output, DecompilationOptions options, ModuleDef module)
		{
			astBuilder.RunTransformations(transformAbortCondition);
			if (options.DecompilerSettings.ShowXmlDocumentation) {
				try {
					AddXmlDocTransform.Run(astBuilder.SyntaxTree);
				} catch (XmlException ex) {
					string[] msg = (" Exception while reading XmlDoc: " + ex.ToString()).Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
					var insertionPoint = astBuilder.SyntaxTree.FirstChild;
					for (int i = 0; i < msg.Length; i++)
						astBuilder.SyntaxTree.InsertChildBefore(insertionPoint, new CSharp.Comment(msg[i], CSharp.CommentType.Documentation), CSharp.Roles.Comment);
				}
			}
			var csharpUnit = astBuilder.SyntaxTree;
			csharpUnit.AcceptVisitor(new NRefactory.CSharp.InsertParenthesesVisitor() { InsertParenthesesForReadability = true });
			var unit = csharpUnit.AcceptVisitor(new CSharpToVBConverterVisitor(new ILSpyEnvironmentProvider()), null);
			var outputFormatter = new VBTextOutputFormatter(output);
			var formattingPolicy = new VBFormattingOptions();
			unit.AcceptVisitor(new OutputVisitor(outputFormatter, formattingPolicy), null);
		}
开发者ID:nakijun,项目名称:dnSpy,代码行数:20,代码来源:VBLanguage.cs

示例11: Decompile

		public static List<ReferenceSegment> Decompile (TextEditor data, ModuleDefinition module, TypeDefinition currentType, Action<AstBuilder> setData, DecompilerSettings settings)
		{
			var context = new DecompilerContext (module);
			var source = new CancellationTokenSource ();
			context.CancellationToken = source.Token;
			context.CurrentType = currentType;
			context.Settings = settings;
			try {
				var astBuilder = new AstBuilder (context);
				setData (astBuilder);
				astBuilder.RunTransformations (o => false);
				GeneratedCodeSettings.Default.Apply (astBuilder.SyntaxTree);
				var output = new ColoredCSharpFormatter (data);
				astBuilder.GenerateCode (output);
				output.SetDocumentData ();
				return output.ReferencedSegments;
			} catch (Exception e) {
				// exception  -> try to decompile without method bodies
				try {
					var astBuilder = new AstBuilder (context);
					astBuilder.DecompileMethodBodies = false;
					setData (astBuilder);
					astBuilder.RunTransformations (o => false);
					GeneratedCodeSettings.Default.Apply (astBuilder.SyntaxTree);
					var output = new ColoredCSharpFormatter (data);
					astBuilder.GenerateCode (output);
					output.SetDocumentData ();
					data.InsertText (data.Length, "/* body decompilation failed: \n" + e + " */"); 
				} catch (Exception e2) {
					data.Text = "/* fallback decompilation failed: \n" + e2 +"*/";
				}
			}
			return null;
		}
开发者ID:pabloescribanoloza,项目名称:monodevelop,代码行数:34,代码来源:DomMethodNodeBuilder.cs

示例12: Run

        void Run(Config config)
        {
            if (config.AssembliesToDecompile.Count == 0) {
                config.ShowHelp = true;
            }

            if (config.ShowHelp) {
                Console.WriteLine ("Netjs compiler, Copyright 2014-2016 Frank A. Krueger");
                Console.WriteLine ("netjs [options] assembly-files");
                Console.WriteLine ("   --help, -h           Show usage information");
                Console.WriteLine ("   --includerefs, -r    Decompile referenced assemblies");
                return;
            }

            string outPath = "";
            var asmPaths = new List<string> ();

            foreach (var asmRelPath in config.AssembliesToDecompile) {
                var asmPath = Path.GetFullPath (asmRelPath);
                asmPaths.Add (asmPath);

                if (string.IsNullOrEmpty (outPath)) {
                    outPath = Path.ChangeExtension (asmPath, ".ts");
                }

                var asmDir = Path.GetDirectoryName (asmPath);
                if (!asmSearchPaths.Exists (x => x.Item1 == asmDir)) {
                    asmSearchPaths.Add (Tuple.Create (asmDir, config.IncludeRefs));
                }
            }

            Step ("Reading IL");
            globalReaderParameters.AssemblyResolver = this;
            globalReaderParameters.ReadingMode = ReadingMode.Immediate;

            var libDir = Path.GetDirectoryName (typeof (String).Assembly.Location);
            asmSearchPaths.Add (Tuple.Create(libDir, false));
            asmSearchPaths.Add (Tuple.Create(Path.Combine (libDir, "Facades"), false));

            AssemblyDefinition firstAsm = null;
            foreach (var asmPath in asmPaths) {
                var asm = AssemblyDefinition.ReadAssembly (asmPath, globalReaderParameters);
                if (firstAsm == null)
                    firstAsm = asm;
                referencedAssemblies[asm.Name.Name] = asm;
                decompileAssemblies.Add (asm);
            }

            Step ("Decompiling IL to C#");
            var context = new DecompilerContext (firstAsm.MainModule);
            context.Settings.ForEachStatement = false;
            context.Settings.ObjectOrCollectionInitializers = false;
            context.Settings.UsingStatement = false;
            context.Settings.AsyncAwait = false;
            context.Settings.AutomaticProperties = true;
            context.Settings.AutomaticEvents = true;
            context.Settings.QueryExpressions = false;
            context.Settings.AlwaysGenerateExceptionVariableForCatchBlocks = true;
            context.Settings.UsingDeclarations = false;
            context.Settings.FullyQualifyAmbiguousTypeNames = true;
            context.Settings.YieldReturn = false;
            var builder = new AstBuilder (context);
            var decompiled = new HashSet<string> ();
            for (;;) {
                var a = decompileAssemblies.FirstOrDefault (x => !decompiled.Contains (x.FullName));
                if (a != null) {
                    Info ("  Decompiling {0}", a.FullName);
                    builder.AddAssembly (a);
                    decompiled.Add (a.FullName);
                }
                else {
                    break;
                }
            }
            builder.RunTransformations ();

            Step ("Translating C# to TypeScript");
            new CsToTs ().Run (builder.SyntaxTree);

            Step ("Writing");
            using (var outputWriter = new StreamWriter (outPath)) {
                var output = new PlainTextOutput (outputWriter);
                builder.GenerateCode (output, (s, e) => new TsOutputVisitor (s, e));
            }

            Step ("Done");
        }
开发者ID:praeclarum,项目名称:Netjs,代码行数:87,代码来源:App.cs

示例13: Decompile

		public static List<ReferenceSegment> Decompile (TextEditorData data, ModuleDefinition module, TypeDefinition currentType, Action<AstBuilder> setData)
		{
			try {
				var types = DesktopService.GetMimeTypeInheritanceChain (data.Document.MimeType);
				var codePolicy = MonoDevelop.Projects.Policies.PolicyService.GetDefaultPolicy<MonoDevelop.CSharp.Formatting.CSharpFormattingPolicy> (types);
				
				var context = new DecompilerContext (module);
				var source = new CancellationTokenSource ();
				
				context.CancellationToken = source.Token;
				context.CurrentType = currentType;
				
				context.Settings = new DecompilerSettings () {
					AnonymousMethods = true,
					AutomaticEvents  = true,
					AutomaticProperties = true,
					ForEachStatement = true,
					LockStatement = true
				};
				
				AstBuilder astBuilder = new AstBuilder (context);
				
				setData (astBuilder);
				
				astBuilder.RunTransformations (o => false);
				var output = new ColoredCSharpFormatter (data.Document);
				astBuilder.GenerateCode (output, codePolicy.CreateOptions ());
				output.SetDocumentData ();
				return output.ReferencedSegments;
			} catch (Exception e) {
				data.Text = "Decompilation failed: \n" + e;
			}
			return null;
		}
开发者ID:yayanyang,项目名称:monodevelop,代码行数:34,代码来源:DomMethodNodeBuilder.cs

示例14: Decompile

		public static List<ReferenceSegment> Decompile (TextEditorData data, ModuleDefinition module, TypeDefinition currentType, Action<AstBuilder> setData, DecompilerSettings settings)
		{
			try {

				var context = new DecompilerContext (module);
				var source = new CancellationTokenSource ();
				
				context.CancellationToken = source.Token;
				context.CurrentType = currentType;
				
				context.Settings = settings;
				
				AstBuilder astBuilder = new AstBuilder (context);
				
				setData (astBuilder);
				
				astBuilder.RunTransformations (o => false);
				GeneratedCodeSettings.Default.Apply (astBuilder.CompilationUnit);
				var output = new ColoredCSharpFormatter (data.Document);
				astBuilder.GenerateCode (output);
				output.SetDocumentData ();
				return output.ReferencedSegments;
			} catch (Exception e) {
				data.Text = "Decompilation failed: \n" + e;
			}
			return null;
		}
开发者ID:rajeshpillai,项目名称:monodevelop,代码行数:27,代码来源:DomMethodNodeBuilder.cs

示例15: RunTransformsAndGenerateCode

		void RunTransformsAndGenerateCode(AstBuilder astBuilder, ITextOutput output, DecompilationOptions options, ModuleDefinition module)
		{
			astBuilder.RunTransformations(transformAbortCondition);
			if (options.DecompilerSettings.ShowXmlDocumentation)
				AddXmlDocTransform.Run(astBuilder.SyntaxTree);
			var csharpUnit = astBuilder.SyntaxTree;
			csharpUnit.AcceptVisitor(new NRefactory.CSharp.InsertParenthesesVisitor() { InsertParenthesesForReadability = true });
			var unit = csharpUnit.AcceptVisitor(new CSharpToVBConverterVisitor(new ILSpyEnvironmentProvider()), null);
			var outputFormatter = new VBTextOutputFormatter(output);
			var formattingPolicy = new VBFormattingOptions();
			unit.AcceptVisitor(new OutputVisitor(outputFormatter, formattingPolicy), null);
		}
开发者ID:rongchunzhang,项目名称:ILSpy,代码行数:12,代码来源:VBLanguage.cs


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