protected virtual void WriteInternal(IMemberDefinition member, bool writeDocumentation, bool showCompilerGeneratedMembers = false) { uint memberToken = member.MetadataToken.ToUInt32(); if (isStopped) return; membersStack.Push(member); if (!(member is TypeDefinition) || (member == CurrentType)) { formatter.PreserveIndent(member); } try { if (writeDocumentation) { int documentationStartIndex = this.formatter.CurrentPosition; WriteDocumentation(member); AddMemberDocumentationOffsetSpan(memberToken, documentationStartIndex, this.formatter.CurrentPosition); } if (member is TypeDefinition) { formatter.WriteMemberDeclaration(member); WriteTypeInANewWriterIfNeeded((TypeDefinition)member, writeDocumentation, showCompilerGeneratedMembers); } else { int attributesStartIndex = this.formatter.CurrentPosition; WriteAttributes(member); AddMemberAttributesOffsetSpan(memberToken, attributesStartIndex, this.formatter.CurrentPosition); int decompiledCodeStartIndex = this.formatter.CurrentPosition; if (member is MethodDefinition) { formatter.WriteMemberDeclaration(member); Write((MethodDefinition)member); } else if (member is PropertyDefinition) { formatter.WriteMemberDeclaration(member); Write((PropertyDefinition)member); } else if (member is EventDefinition) { formatter.WriteMemberDeclaration(member); Write((EventDefinition)member); } else if (member is FieldDefinition) { formatter.WriteMemberDeclaration(member); Write((FieldDefinition)member); } this.currentWritingInfo.MemberTokenToDecompiledCodeMap.Add(memberToken, new OffsetSpan(decompiledCodeStartIndex, this.formatter.CurrentPosition - 1)); } } catch (Exception ex) { ExceptionStatement exceptionStatement = new ExceptionStatement(ex, member); Visit(exceptionStatement); formatter.RestoreIndent(member); this.currentWritingInfo.ExceptionsWhileWriting.Add(member); this.currentWritingInfo.MembersWithExceptions.Add(memberToken); if (member is PropertyDefinition) { PropertyDefinition property = member as PropertyDefinition; if (property.GetMethod != null) { this.currentWritingInfo.ExceptionsWhileWriting.Add(property.GetMethod); } if (property.SetMethod != null) { this.currentWritingInfo.ExceptionsWhileWriting.Add(property.SetMethod); } } if (member is EventDefinition) { EventDefinition @event = member as EventDefinition; if (@event.AddMethod != null) { this.currentWritingInfo.ExceptionsWhileWriting.Add(@event.AddMethod); } if (@event.RemoveMethod != null) { this.currentWritingInfo.ExceptionsWhileWriting.Add(@event.RemoveMethod); } if (@event.InvokeMethod != null) { this.currentWritingInfo.ExceptionsWhileWriting.Add(@event.InvokeMethod); } } } if (!(member is TypeDefinition) || (member == CurrentType)) { formatter.RemovePreservedIndent(member); } membersStack.Pop(); }
private CachedDecompiledMember DecompileMethod(ILanguage language, MethodDefinition method, TypeSpecificContext typeContext) { CachedDecompiledMember decompiledMember; Statement statement; try { DecompilationContext innerContext = null; statement = method.Body.Decompile(language, out innerContext, typeContext); decompiledMember = new CachedDecompiledMember(new DecompiledMember(Utilities.GetMemberUniqueName(method), statement, innerContext.MethodContext), innerContext.TypeContext); } catch (Exception ex) { this.ExceptionsWhileDecompiling.Add(method); BlockStatement blockStatement = new BlockStatement(); statement = new ExceptionStatement(ex, method); blockStatement.AddStatement(statement); decompiledMember = new CachedDecompiledMember(new DecompiledMember(Utilities.GetMemberUniqueName(method), blockStatement, new MethodSpecificContext(method.Body))); } return decompiledMember; }
public override void VisitExceptionStatement(ExceptionStatement node) { WriteException(new Exception("Exception in: " + node.Member.GetFullMemberName(Language), node.ExceptionObject), node.Member); }
public virtual void VisitExceptionStatement(ExceptionStatement node) { }