DecompileMethod() public method

public DecompileMethod ( Mono.Cecil.MethodDefinition method, ITextOutput output, DecompilationOptions options ) : void
method Mono.Cecil.MethodDefinition
output ITextOutput
options DecompilationOptions
return void
        public string Decompile(object @object)
        {
            if (@object == null) return String.Empty;
            Language l = new CSharpLanguage();

            ITextOutput output = new RtfTextOutput();
            var options = new DecompilationOptions();

            if (@object is AssemblyDefinition)
                l.DecompileAssembly((AssemblyDefinition)@object, output, options);
            else if (@object is TypeDefinition)
                l.DecompileType((TypeDefinition)@object, output, options);
            else if (@object is MethodDefinition)
                l.DecompileMethod((MethodDefinition)@object, output, options);
            else if (@object is FieldDefinition)
                l.DecompileField((FieldDefinition)@object, output, options);
            else if (@object is PropertyDefinition)
                l.DecompileProperty((PropertyDefinition)@object, output, options);
            else if (@object is EventDefinition)
                l.DecompileEvent((EventDefinition)@object, output, options);
            else if (@object is AssemblyNameReference)
            {
                output.Write("// Assembly Reference ");
                output.WriteDefinition(@object.ToString(), null);
                output.WriteLine();
            }
            else if(@object is ModuleReference)
            {
                output.Write("// Module Reference ");
                output.WriteDefinition(@object.ToString(), null);
                output.WriteLine();
            }
            else
            {
                output.Write(String.Format("// {0} ", @object.GetType().Name));
                output.WriteDefinition(@object.ToString(), null);
                output.WriteLine();
            }

            return output.ToString();
        }
        public string getSourceCode(MethodDefinition methodDefinition)
        {
            try
            {
	            var csharpLanguage = new CSharpLanguage();
				var textOutput = new PlainTextOutput();
				var decompilationOptions = new DecompilationOptions();
 				decompilationOptions.FullDecompilation = true;
				csharpLanguage.DecompileMethod(methodDefinition, textOutput, decompilationOptions);
				return textOutput.ToString();
            	
             /*   ILanguage language = CSharp.GetLanguage(CSharpVersion.V1);
                language.GetWriter(new PlainTextFormatter(writer)).Write(method);
                MemoryStream stream = new MemoryStream();
                StreamWriter writer3 = new StreamWriter(stream);
                language.GetWriter(new PlainTextFormatter(writer3)).Write(method);
                stream.Flush();*/
                
            }
            catch (Exception exception)
            {
                PublicDI.log.error("in getSourceCode: {0}", new object[] { exception.Message });
                return ("Error in creating source code from IL: " + exception.Message);
            }
        }
Beispiel #3
0
		private void SetupDecompilerAndOriginalSource(MethodDefinition method)
		{
			_cSharpDecompiler = new CSharpLanguage();
            var decompilationOutput = new PlainTextOutput();
            _decompilationOptions = new DecompilationOptions();
            _cSharpDecompiler.DecompileMethod(method, decompilationOutput, _decompilationOptions);
            _oldText = decompilationOutput.ToString();
            _differ = new SideBySideDiffBuilder(new Differ());
		}