public static MethodBodyInfo Create(MethodBase method) { MethodBodyInfo mbi = new MethodBodyInfo(); mbi.Identity = method.GetHashCode(); mbi.TypeName = method.GetType().Name; mbi.MethodToString = method.ToString(); ReadableILStringVisitor readableIlStringVisitor = new ReadableILStringVisitor((IILStringCollector) new MethodBodyInfo.MethodBodyInfoBuilder(mbi), (IFormatProvider)DefaultFormatProvider.Instance); new ILReader(method).Accept((ILInstructionVisitor)readableIlStringVisitor); return(mbi); }
protected override void DoChecks(MethodBase mehodBeingChecked, MethodBodyInfo methodBody, Dependency parent) { foreach (ILInstruction instruction in methodBody.Instructions) { if (instruction is InlineMethodInstruction) { InlineMethodInstruction line = instruction as InlineMethodInstruction; if (line.Method.IsVirtual) { parent.Add(new VirtualMethodCallDependency(line.Method.ReflectedType.Name, line.Method.Name)); } } } }
protected override void DoChecks(MethodBase mehodBeingChecked, MethodBodyInfo methodBody, Dependency parent) { foreach (ILInstruction instruction in methodBody.Instructions) { if (instruction is InlineMethodInstruction) { InlineMethodInstruction line = instruction as InlineMethodInstruction; if (line.Method.IsStatic) { string message = string.Format("Static method call {0} on {1}", line.Method.Name, line.Method.ReflectedType.Name); parent.Add(new ProblemDependency(message)); } } } }
public MethodBodyInfoBuilder(MethodBodyInfo mbi) { m_mbi = mbi; m_indent = ""; m_starts = new HashSet<int>(); m_ends = new HashSet<int>(); m_startFinally = new HashSet<int>(); m_startFault = new HashSet<int>(); m_startFilter = new HashSet<int>(); m_startCatch = new Dictionary<int, Type>(); m_endCatch = new HashSet<int>(); foreach (var e in mbi.Exceptions) { var finallyOrFault = e.Handlers.Count(h => h.Kind == HandlerKind.Finally || h.Kind == HandlerKind.Fault); var numberOfCatch = e.Handlers.Length - finallyOrFault; m_starts.Add(e.StartAddress); m_ends.Add(e.EndAddress); foreach (var c in e.Handlers) { if (c.Kind == HandlerKind.Finally) { m_startFinally.Add(c.StartAddress); } else if (c.Kind == HandlerKind.Fault) { m_startFault.Add(c.StartAddress); } else if (c.Kind == HandlerKind.Filter) { m_startFilter.Add(c.StartAddress); } else { m_startCatch.Add(c.StartAddress, c.Type); } m_endCatch.Add(c.EndAddress); } } }
public static MethodBodyInfo Create(MethodBase method) { MethodBodyInfo mbi = new MethodBodyInfo(); mbi.Identity = method.GetHashCode(); mbi.TypeName = method.GetType().Name; mbi.MethodToString = ".method " + method.ToIL(); ILReader reader = ILReaderFactory.Create(method); mbi.Exceptions = reader.ILProvider.GetExceptionInfos(); ReadableILStringVisitor visitor = new ReadableILStringVisitor( new MethodBodyInfoBuilder(mbi), DefaultFormatProvider.Instance); reader.Accept(visitor); return mbi; }
public MethodBodyInfoBuilder(MethodBodyInfo mbi) { m_mbi = mbi; m_indent = ""; m_starts = new HashSet <int>(); m_ends = new HashSet <int>(); m_startFinally = new HashSet <int>(); m_startFault = new HashSet <int>(); m_startFilter = new HashSet <int>(); m_startCatch = new Dictionary <int, Type>(); m_endCatch = new HashSet <int>(); foreach (var e in mbi.Exceptions) { var finallyOrFault = e.Handlers.Count(h => h.Kind == HandlerKind.Finally || h.Kind == HandlerKind.Fault); var numberOfCatch = e.Handlers.Length - finallyOrFault; m_starts.Add(e.StartAddress); m_ends.Add(e.EndAddress); foreach (var c in e.Handlers) { if (c.Kind == HandlerKind.Finally) { m_startFinally.Add(c.StartAddress); } else if (c.Kind == HandlerKind.Fault) { m_startFault.Add(c.StartAddress); } else if (c.Kind == HandlerKind.Filter) { m_startFilter.Add(c.StartAddress); } else { m_startCatch.Add(c.StartAddress, c.Type); } m_endCatch.Add(c.EndAddress); } } }
public static MethodBodyInfo Create(MethodBase method) { MethodBodyInfo mbi = new MethodBodyInfo(); mbi.Identity = method.GetHashCode(); mbi.TypeName = method.GetType().Name; mbi.MethodToString = ".method " + method.ToIL(); ILReader reader = ILReaderFactory.Create(method); mbi.Exceptions = reader.ILProvider.GetExceptionInfos(); ReadableILStringVisitor visitor = new ReadableILStringVisitor( new MethodBodyInfoBuilder(mbi), DefaultFormatProvider.Instance); reader.Accept(visitor); return(mbi); }
public MethodBodyInfoBuilder(MethodBodyInfo mbi) { this.m_mbi = mbi; }
public static MethodBodyInfo Create(MethodBase method) { MethodBodyInfo mbi = new MethodBodyInfo(); mbi.Identity = method.GetHashCode(); mbi.TypeName = method.GetType().Name; mbi.MethodToString = method.ToString(); ReadableILStringVisitor readableIlStringVisitor = new ReadableILStringVisitor((IILStringCollector) new MethodBodyInfo.MethodBodyInfoBuilder(mbi), (IFormatProvider) DefaultFormatProvider.Instance); new ILReader(method).Accept((ILInstructionVisitor) readableIlStringVisitor); return mbi; }