public override void DecompileProperty(PropertyDefinition property, ITextOutput output, DecompilationOptions options) { WriteCommentLine(output, TypeToString(property.DeclaringType, includeNamespace: true)); AstBuilder codeDomBuilder = CreateAstBuilder(options, currentType: property.DeclaringType, isSingleMember: true); codeDomBuilder.AddProperty(property); RunTransformsAndGenerateCode(codeDomBuilder, output, options, property.Module); }
public void DecompileProperty(PropertyDefinition property, ITextOutput output, DecompilerSettings options) { AstBuilder codeDomBuilder = CreateAstBuilder(options, currentType: property.DeclaringType, isSingleMember: true); codeDomBuilder.AddProperty(property); RunTransformsAndGenerateCode(codeDomBuilder, output, options); }
public override void DecompileProperty(PropertyDefinition property, ITextOutput output, DecompilationOptions options) { AstBuilder codeDomBuilder = CreateAstBuilder(options, property.DeclaringType); codeDomBuilder.AddProperty(property); codeDomBuilder.GenerateCode(output, transformAbortCondition); }
public override void DecompileProperty(PropertyDefinition property, ITextOutput output, DecompilationOptions options) { WriteCommentLine(output, TypeToString(property.DeclaringType, includeNamespace: true)); AstBuilder codeDomBuilder = CreateAstBuilder(options, property.DeclaringType); codeDomBuilder.AddProperty(property); codeDomBuilder.GenerateCode(output, transformAbortCondition); }
public override void Decompile(PropertyDef property, ITextOutput output, DecompilationContext ctx) { WriteCommentLineDeclaringType(output, property); AstBuilder codeDomBuilder = CreateAstBuilder(ctx, langSettings.Settings, currentType: property.DeclaringType, isSingleMember: true); codeDomBuilder.AddProperty(property); RunTransformsAndGenerateCode(codeDomBuilder, output, ctx); }
public static AstNode getPropertyDeclaration(PropertyDefinition property) { AstBuilder codeDomBuilder = CreateAstBuilder(currentType: property.DeclaringType, isSingleMember: true); codeDomBuilder.AddProperty(property); RunTransformsAndGenerateCode(codeDomBuilder); codeDomBuilder.SyntaxTree.AcceptVisitor(new InsertParenthesesVisitor { InsertParenthesesForReadability = true }); return(codeDomBuilder.SyntaxTree.Members.ToList()[0]); }
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.SyntaxTree.Descendants.OfType <AttributeSection>()) { attribute.Remove(); } StringWriter w = new StringWriter(); b.SyntaxTree.AcceptVisitor(new InsertParenthesesVisitor { InsertParenthesesForReadability = true }); GenerateCode(b.SyntaxTree, new PlainTextOutput(w)); return(Regex.Replace(w.ToString(), @"\s+", " ").TrimEnd()); } return(base.GetTooltip(member)); }
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.SyntaxTree.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); }
AstBuilder CreateBuilder(IDnlibDef item, CancellationToken token) { ModuleDef moduleDef; DecompilerContext ctx; AstBuilder builder; if (item is ModuleDef) { var def = (ModuleDef)item; moduleDef = def; builder = new AstBuilder(ctx = new DecompilerContext(moduleDef) { CancellationToken = token }); builder.AddAssembly(def, true); } else if (item is TypeDef) { var def = (TypeDef)item; moduleDef = def.Module; builder = new AstBuilder(ctx = new DecompilerContext(moduleDef) { CancellationToken = token }); builder.DecompileMethodBodies = false; ctx.CurrentType = def; builder.AddType(def); } else if (item is MethodDef) { var def = (MethodDef)item; moduleDef = def.Module; builder = new AstBuilder(ctx = new DecompilerContext(moduleDef) { CancellationToken = token }); ctx.CurrentType = def.DeclaringType; builder.AddMethod(def); } else if (item is FieldDef) { var def = (FieldDef)item; moduleDef = def.Module; builder = new AstBuilder(ctx = new DecompilerContext(moduleDef) { CancellationToken = token }); ctx.CurrentType = def.DeclaringType; builder.AddField(def); } else if (item is PropertyDef) { var def = (PropertyDef)item; moduleDef = def.Module; builder = new AstBuilder(ctx = new DecompilerContext(moduleDef) { CancellationToken = token }); ctx.CurrentType = def.DeclaringType; builder.AddProperty(def); } else if (item is EventDef) { var def = (EventDef)item; moduleDef = def.Module; builder = new AstBuilder(ctx = new DecompilerContext(moduleDef) { CancellationToken = token }); ctx.CurrentType = def.DeclaringType; builder.AddEvent(def); } else { return(null); } ctx.Settings = new DecompilerSettings { UsingDeclarations = false }; return(builder); }
public ICSharpCode.AvalonEdit.Document.TextDocument Decompile(object obj) { AvalonEditTextOutput aeto = new AvalonEditTextOutput(); AstBuilder ast = new AstBuilder(new DecompilerContext(ModuleDefinition.CreateModule("ash", ModuleKind.NetModule))); switch (obj.GetType().Name) { case "AssemblyDefinition": ast = new AstBuilder(new DecompilerContext((obj as AssemblyDefinition).MainModule) { Settings = new DecompilerSettings() }); try { ast.AddAssembly(obj as AssemblyDefinition); } catch (AssemblyResolutionException e) { MessageBox.Show("Could not load assembly " + e.AssemblyReference.FullName); } break; case "TypeDefinition": ast = CreateAstBuilder((obj as TypeDefinition), true); try { ast.AddType(obj as TypeDefinition); } catch (AssemblyResolutionException e) { MessageBox.Show("Could not load assembly " + e.AssemblyReference.FullName); } break; case "MethodDefinition": MethodDefinition method = (obj as MethodDefinition); ast = CreateAstBuilder(method.DeclaringType, true); if (method.IsConstructor && !method.IsStatic && !method.DeclaringType.IsValueType) { foreach (var field in method.DeclaringType.Fields) { if (field.IsStatic == method.IsStatic) { try { ast.AddField(field); } catch (AssemblyResolutionException e) { MessageBox.Show("Could not load assembly " + e.AssemblyReference.Name); } } } foreach (var ctor in method.DeclaringType.Methods) { if (ctor.IsConstructor && ctor.IsStatic == method.IsStatic) { try { ast.AddMethod(ctor); } catch (AssemblyResolutionException e) { MessageBox.Show("Could not load assembly " + e.AssemblyReference.Name); } } } } else { try { ast.AddMethod(obj as MethodDefinition); } catch (AssemblyResolutionException e) { MessageBox.Show("Could not load assembly " + e.AssemblyReference.Name); } } break; case "PropertyDefinition": ast = CreateAstBuilder((obj as PropertyDefinition).DeclaringType, true); try { ast.AddProperty(obj as PropertyDefinition); } catch (AssemblyResolutionException e) { MessageBox.Show("Could not load assembly " + e.AssemblyReference.Name); } break; case "FieldDefinition": ast = CreateAstBuilder((obj as FieldDefinition).DeclaringType, true); try { ast.AddField(obj as FieldDefinition); } catch (AssemblyResolutionException e) { MessageBox.Show("Could not load assembly " + e.AssemblyReference.Name); } break; case "EventDefinition": ast = CreateAstBuilder((obj as EventDefinition).DeclaringType, true); try { ast.AddEvent(obj as EventDefinition); } catch (AssemblyResolutionException e) { MessageBox.Show("Could not load assembly " + e.AssemblyReference.Name); } break; default: return(new ICSharpCode.AvalonEdit.Document.TextDocument()); } try { ast.GenerateCode(aeto); } catch (AssemblyResolutionException e) { MessageBox.Show("Could not load assembly upon code generation:\r" + e.AssemblyReference.FullName); } return(aeto.GetDocument()); }