private IEnumerable <AnalyzerTreeNode> FindReferencesInType(TypeDefinition type) { if (!type.HasInterfaces) { yield break; } TypeReference implementedInterfaceRef = type.Interfaces.FirstOrDefault(i => i.Resolve() == analyzedMethod.DeclaringType); if (implementedInterfaceRef == null) { yield break; } foreach (MethodDefinition method in type.Methods.Where(m => m.Name == analyzedMethod.Name)) { if (TypesHierarchyHelpers.MatchInterfaceMethod(method, analyzedMethod, implementedInterfaceRef)) { var node = new AnalyzedMethodTreeNode(method); node.Language = this.Language; yield return(node); } yield break; } foreach (MethodDefinition method in type.Methods) { if (method.HasOverrides && method.Overrides.Any(m => m.Resolve() == analyzedMethod)) { var node = new AnalyzedMethodTreeNode(method); node.Language = this.Language; yield return(node); } } }
private IEnumerable <SharpTreeNode> FindReferences(LoadedAssembly asm, CancellationToken ct) { string asmName = asm.AssemblyDefinition.Name.Name; string name = analyzedEvent.Name; string declTypeName = analyzedEvent.DeclaringType.FullName; foreach (TypeDefinition type in TreeTraversal.PreOrder(asm.AssemblyDefinition.MainModule.Types, t => t.NestedTypes)) { ct.ThrowIfCancellationRequested(); if (!TypesHierarchyHelpers.IsBaseType(analyzedEvent.DeclaringType, type, resolveTypeArguments: false)) { continue; } foreach (EventDefinition eventDef in type.Events) { ct.ThrowIfCancellationRequested(); if (TypesHierarchyHelpers.IsBaseEvent(analyzedEvent, eventDef)) { MethodDefinition anyAccessor = eventDef.AddMethod ?? eventDef.RemoveMethod; bool hidesParent = !anyAccessor.IsVirtual ^ anyAccessor.IsNewSlot; yield return(new AnalyzedEventTreeNode(eventDef, hidesParent ? "(hides) " : "")); } } } }
private void InitializeAnalyzer() { foundMethods = new ConcurrentDictionary <MethodDef, int>(); var baseMethods = TypesHierarchyHelpers.FindBaseMethods(analyzedMethod).ToArray(); if (baseMethods.Length > 0) { baseMethod = baseMethods[baseMethods.Length - 1]; } else { baseMethod = analyzedMethod; } possibleTypes = new List <ITypeDefOrRef>(); ITypeDefOrRef type = analyzedMethod.DeclaringType.BaseType; while (type != null) { possibleTypes.Add(type); var resolvedType = type.ResolveTypeDef(); type = resolvedType == null ? null : resolvedType.BaseType; } }
protected override IEnumerable <AnalyzerTreeNodeData> FetchChildren(CancellationToken ct) { AddTypeEquivalentTypes(Context.DocumentService, analyzedTypes[0], analyzedTypes); foreach (var declType in analyzedTypes) { var type = declType.BaseType.ResolveTypeDef(); while (!(type is null)) { foreach (var property in type.Properties) { if (TypesHierarchyHelpers.IsBaseProperty(property, analyzedProperty)) { var anyAccessor = property.GetMethod ?? property.SetMethod; if (anyAccessor is null) { continue; } yield return(new PropertyNode(property) { Context = Context }); yield break; } } type = type.BaseType.ResolveTypeDef(); } } }
private IEnumerable <SharpTreeNode> FindReferencesInType(TypeDefinition type) { if (!type.HasInterfaces) { yield break; } TypeReference implementedInterfaceRef = type.Interfaces.FirstOrDefault(i => i.Resolve() == analyzedMethod.DeclaringType); if (implementedInterfaceRef == null) { yield break; } foreach (PropertyDefinition property in type.Properties.Where(e => e.Name == analyzedProperty.Name)) { MethodDefinition accessor = property.GetMethod ?? property.SetMethod; if (TypesHierarchyHelpers.MatchInterfaceMethod(accessor, analyzedMethod, implementedInterfaceRef)) { yield return(new AnalyzedPropertyTreeNode(property)); } yield break; } foreach (PropertyDefinition property in type.Properties.Where(e => e.Name.EndsWith(analyzedProperty.Name))) { MethodDefinition accessor = property.GetMethod ?? property.SetMethod; if (accessor.HasOverrides && accessor.Overrides.Any(m => m.Resolve() == analyzedMethod)) { yield return(new AnalyzedPropertyTreeNode(property)); } } }
private void InitializeAnalyzer() { foundMethods = new ConcurrentDictionary <MethodDefinition, int>(); var BaseMethods = TypesHierarchyHelpers.FindBaseMethods(analyzedMethod).ToArray(); if (BaseMethods.Length > 0) { baseMethod = BaseMethods[BaseMethods.Length - 1]; } else { baseMethod = analyzedMethod; } possibleTypes = new List <TypeReference>(); TypeReference type = analyzedMethod.DeclaringType.BaseType; while (type != null) { possibleTypes.Add(type); type = type.Resolve().BaseType; } }
private IEnumerable <AnalyzerTreeNode> FindReferencesInType(TypeDef type) { AnalyzerTreeNode newNode = null; try { if (!TypesHierarchyHelpers.IsBaseType(analyzedMethod.DeclaringType, type, resolveTypeArguments: false)) { yield break; } foreach (MethodDef method in type.Methods) { if (TypesHierarchyHelpers.IsBaseMethod(analyzedMethod, method)) { bool hidesParent = !method.IsVirtual ^ method.IsNewSlot; newNode = new AnalyzedMethodTreeNode(method, hidesParent); } } } catch (ResolveException) { // ignore this type definition. maybe add a notification about such cases. } if (newNode != null) { newNode.Language = this.Language; yield return(newNode); } }
protected override IEnumerable <AnalyzerTreeNodeData> FetchChildren(CancellationToken ct) { AddTypeEquivalentTypes(Context.DocumentService, analyzedTypes[0], analyzedTypes); foreach (var declType in analyzedTypes) { var type = declType.BaseType.ResolveTypeDef(); while (!(type is null)) { foreach (var eventDef in type.Events) { if (TypesHierarchyHelpers.IsBaseEvent(eventDef, analyzedEvent)) { var anyAccessor = eventDef.AddMethod ?? eventDef.RemoveMethod; if (anyAccessor is null) { continue; } yield return(new EventNode(eventDef) { Context = Context }); yield break; } } type = type.BaseType.ResolveTypeDef(); } } }
IEnumerable <AnalyzerTreeNodeData> FindReferencesInType(TypeDef type) { if (analyzedMethod is null) { yield break; } if (type.IsInterface) { yield break; } var implementedInterfaceRef = InterfaceMethodImplementedByNode.GetInterface(type, analyzedMethod.DeclaringType); if (implementedInterfaceRef is null) { yield break; } foreach (EventDef ev in type.Events.Where(e => e.Name.EndsWith(analyzedEvent.Name))) { var accessor = GetAccessor(ev); // Don't include abstract accessors, they don't implement anything if (accessor is null || !accessor.IsVirtual || accessor.IsAbstract) { continue; } if (accessor.HasOverrides && accessor.Overrides.Any(m => CheckEquals(m.MethodDeclaration.ResolveMethodDef(), analyzedMethod))) { yield return(new EventNode(ev) { Context = Context }); yield break; } } foreach (EventDef ev in type.Events.Where(e => e.Name == analyzedEvent.Name)) { var accessor = GetAccessor(ev); // Don't include abstract accessors, they don't implement anything if (accessor is null || !accessor.IsVirtual || accessor.IsAbstract) { continue; } if (TypesHierarchyHelpers.MatchInterfaceMethod(accessor, analyzedMethod, implementedInterfaceRef)) { yield return(new EventNode(ev) { Context = Context }); yield break; } } }
bool IsAssignableTo(TypeDefinition from, TypeDefinition to) { if (to.IsInterface) { return(from.Interfaces.Any(x => x.InterfaceType == to)); } else { return(TypesHierarchyHelpers.IsBaseType(to, from, false)); } }
protected override IEnumerable <AnalyzerTreeNodeData> FetchChildren(CancellationToken ct) { //note: only goes up 1 level AnalyzerTreeNodeData newNode = null; try { //get base type (if any) if (analyzedMethod.DeclaringType.BaseType == null) { yield break; } ITypeDefOrRef baseType = analyzedMethod.DeclaringType.BaseType; while (baseType != null) { //only typedef has a Methods property if (baseType is TypeDef) { TypeDef def = (TypeDef)baseType; foreach (var method in def.Methods) { if (TypesHierarchyHelpers.IsBaseMethod(method, analyzedMethod)) { newNode = new MethodNode(method) { Context = Context }; break; //there can be only one } } //escape from the while loop if we have a match (cannot yield return in try/catch) if (newNode != null) { break; } baseType = def.BaseType; } else { //try to resolve the TypeRef //will be null if resolving failed baseType = baseType.Resolve(); } } } catch (ResolveException) { //ignored } if (newNode != null) { yield return(newNode); } }
void InitializeAnalyzer() { foundMethods = new ConcurrentDictionary <MethodDef, int>(); var baseMethods = TypesHierarchyHelpers.FindBaseMethods(analyzedMethod).ToArray(); if (baseMethods.Length > 0) { baseMethod = baseMethods[baseMethods.Length - 1]; } else { baseMethod = analyzedMethod; } }
private IEnumerable<AnalyzerTreeNode> FindReferencesInType(TypeDefinition type) { if (!TypesHierarchyHelpers.IsBaseType(analyzedEvent.DeclaringType, type, resolveTypeArguments: false)) yield break; foreach (EventDefinition eventDef in type.Events) { if (TypesHierarchyHelpers.IsBaseEvent(analyzedEvent, eventDef)) { MethodDefinition anyAccessor = eventDef.AddMethod ?? eventDef.RemoveMethod; bool hidesParent = !anyAccessor.IsVirtual ^ anyAccessor.IsNewSlot; var node = new AnalyzedEventTreeNode(eventDef, hidesParent ? "(hides) " : ""); node.Language = this.Language; yield return node; } } }
static bool Impl(MethodDef method, MethodDef ifaceMethod) { if (method.HasOverrides) { var comparer = new SigComparer(SigComparerOptions.CompareDeclaringTypes | SigComparerOptions.PrivateScopeIsComparable); if (method.Overrides.Any(m => comparer.Equals(m.MethodDeclaration, ifaceMethod))) { return(true); } } if (method.Name != ifaceMethod.Name) { return(false); } return(TypesHierarchyHelpers.MatchInterfaceMethod(method, ifaceMethod, ifaceMethod.DeclaringType)); }
protected override IEnumerable <AnalyzerTreeNodeData> FetchChildren(CancellationToken ct) { AddTypeEquivalentTypes(Context.DocumentService, analyzedTypes[0], analyzedTypes); foreach (var declType in analyzedTypes) { var analyzedAccessor = GetVirtualAccessor(analyzedEvent.AddMethod) ?? GetVirtualAccessor(analyzedEvent.RemoveMethod) ?? GetVirtualAccessor(analyzedEvent.InvokeMethod); if (analyzedAccessor?.Overrides is IList <MethodOverride> overrides && overrides.Count > 0) { bool matched = false; foreach (var o in overrides) { if (o.MethodDeclaration.ResolveMethodDef() is MethodDef method && (method.IsVirtual || method.IsAbstract)) { if (method.DeclaringType.Events.FirstOrDefault(a => (object?)a.AddMethod == method || (object?)a.RemoveMethod == method || (object?)a.InvokeMethod == method) is EventDef eventDef) { matched = true; yield return(new EventNode(eventDef) { Context = Context }); } } } if (matched) { yield break; } } foreach (var eventDef in TypesHierarchyHelpers.FindBaseEvents(analyzedEvent, declType)) { var anyAccessor = GetVirtualAccessor(eventDef.AddMethod) ?? GetVirtualAccessor(eventDef.RemoveMethod) ?? GetVirtualAccessor(eventDef.InvokeMethod); if (anyAccessor is null || !(anyAccessor.IsVirtual || anyAccessor.IsAbstract)) { continue; } yield return(new EventNode(eventDef) { Context = Context }); yield break; } } }
IEnumerable <IAnalyzerTreeNodeData> FindReferencesInType(TypeDef type) { if (analyzedMethod == null) { yield break; } if (!type.HasInterfaces) { yield break; } var iff = type.Interfaces.FirstOrDefault(i => new SigComparer().Equals(i.Interface, analyzedMethod.DeclaringType)); ITypeDefOrRef implementedInterfaceRef = iff == null ? null : iff.Interface; if (implementedInterfaceRef == null) { yield break; } //TODO: Can we compare property sigs too? foreach (PropertyDef property in type.Properties.Where(e => e.Name == analyzedProperty.Name)) { MethodDef accessor = property.GetMethod ?? property.SetMethod; if (accessor != null && TypesHierarchyHelpers.MatchInterfaceMethod(accessor, analyzedMethod, implementedInterfaceRef)) { yield return(new PropertyNode(property) { Context = Context }); } yield break; } foreach (PropertyDef property in type.Properties.Where(e => e.Name.EndsWith(analyzedProperty.Name))) { MethodDef accessor = property.GetMethod ?? property.SetMethod; if (accessor != null && accessor.HasOverrides && accessor.Overrides.Any(m => m.MethodDeclaration.ResolveMethodDef() == analyzedMethod)) { yield return(new PropertyNode(property) { Context = Context }); } } }
private IEnumerable <AnalyzerTreeNode> FindReferencesInType(TypeDef type) { if (!TypesHierarchyHelpers.IsBaseType(analyzedProperty.DeclaringType, type, resolveTypeArguments: false)) { yield break; } foreach (PropertyDef property in type.Properties) { if (TypesHierarchyHelpers.IsBaseProperty(analyzedProperty, property)) { MethodDef anyAccessor = property.GetMethod ?? property.SetMethod; bool hidesParent = !anyAccessor.IsVirtual ^ anyAccessor.IsNewSlot; var node = new AnalyzedPropertyTreeNode(property, hidesParent ? "(hides) " : ""); node.Language = this.Language; yield return(node); } } }
private IEnumerable <AnalyzerTreeNode> FindReferencesInType(TypeDef type) { if (analyzedMethod == null) { yield break; } if (!type.HasInterfaces) { yield break; } var iff = type.Interfaces.FirstOrDefault(i => new SigComparer().Equals(i.Interface, analyzedMethod.DeclaringType)); ITypeDefOrRef implementedInterfaceRef = iff == null ? null : iff.Interface; if (implementedInterfaceRef == null) { yield break; } //TODO: Can we compare property sigs too? foreach (PropertyDef property in type.Properties.Where(e => e.Name == analyzedProperty.Name)) { MethodDef accessor = property.GetMethod ?? property.SetMethod; if (accessor != null && TypesHierarchyHelpers.MatchInterfaceMethod(accessor, analyzedMethod, implementedInterfaceRef)) { var node = new AnalyzedPropertyTreeNode(property); node.Language = this.Language; yield return(node); } yield break; } foreach (PropertyDef property in type.Properties.Where(e => e.Name.EndsWith(analyzedProperty.Name))) { MethodDef accessor = property.GetMethod ?? property.SetMethod; if (accessor != null && accessor.HasOverrides && accessor.Overrides.Any(m => new SigComparer(SigComparerOptions.CompareDeclaringTypes | SigComparerOptions.PrivateScopeIsComparable).Equals(m.MethodDeclaration, analyzedMethod))) { var node = new AnalyzedPropertyTreeNode(property); node.Language = this.Language; yield return(node); } } }
protected override IEnumerable <AnalyzerTreeNodeData> FetchChildren(CancellationToken ct) { //get base type (if any) if (analyzedProperty.DeclaringType.BaseType == null) { yield break; } ITypeDefOrRef baseType = analyzedProperty.DeclaringType.BaseType; while (baseType != null) { //only typedef has a Properties property if (baseType is TypeDef) { TypeDef def = (TypeDef)baseType; foreach (PropertyDef property in def.Properties) { if (TypesHierarchyHelpers.IsBaseProperty(property, analyzedProperty)) { MethodDef anyAccessor = property.GetMethod ?? property.SetMethod; if (anyAccessor == null) { continue; } yield return(new PropertyNode(property) { Context = Context }); yield break; } } baseType = def.BaseType; } else { //try to resolve the TypeRef //will be null if resolving failed baseType = baseType.Resolve(); } } }
protected override IEnumerable <AnalyzerTreeNodeData> FetchChildren(CancellationToken ct) { //get base type (if any) if (analyzedEvent.DeclaringType.BaseType == null) { yield break; } ITypeDefOrRef baseType = analyzedEvent.DeclaringType.BaseType; while (baseType != null) { //only typedef has a Events property if (baseType is TypeDef) { TypeDef def = (TypeDef)baseType; foreach (EventDef eventDef in def.Events) { if (TypesHierarchyHelpers.IsBaseEvent(eventDef, analyzedEvent)) { MethodDef anyAccessor = eventDef.AddMethod ?? eventDef.RemoveMethod; if (anyAccessor == null) { continue; } yield return(new EventNode(eventDef) { Context = Context }); yield break; } } baseType = def.BaseType; } else { //try to resolve the TypeRef //will be null if resolving failed baseType = baseType.Resolve(); } } }
IEnumerable <IAnalyzerTreeNodeData> FindReferencesInType(TypeDef type) { foreach (MethodDef method in type.Methods) { if (!method.HasBody) { continue; } // ignore chained constructors // (since object is the root of everything, we can short circuit the test in this case) if (method.Name == ".ctor" && (isSystemObject || analyzedType == type || TypesHierarchyHelpers.IsBaseType(analyzedType, type, false))) { continue; } Instruction foundInstr = null; foreach (Instruction instr in method.Body.Instructions) { IMethod mr = instr.Operand as IMethod; if (mr != null && !mr.IsField && mr.Name == ".ctor") { if (Helpers.IsReferencedBy(analyzedType, mr.DeclaringType)) { foundInstr = instr; break; } } } if (foundInstr != null) { yield return new MethodNode(method) { Context = Context, SourceRef = new SourceRef(method, foundInstr.Offset, foundInstr.Operand as IMDTokenProvider) } } ; } }
protected override IEnumerable <AnalyzerTreeNodeData> FetchChildren(CancellationToken ct) { AddTypeEquivalentTypes(Context.DocumentService, analyzedTypes[0], analyzedTypes); var overrides = analyzedMethod.Overrides; foreach (var declType in analyzedTypes) { if (overrides.Count > 0) { bool matched = false; foreach (var o in overrides) { if (o.MethodDeclaration.ResolveMethodDef() is MethodDef method && (method.IsVirtual || method.IsAbstract)) { matched = true; yield return(new MethodNode(method) { Context = Context }); } } if (matched) { yield break; } } foreach (var method in TypesHierarchyHelpers.FindBaseMethods(analyzedMethod, declType)) { if (!(method.IsVirtual || method.IsAbstract)) { continue; } yield return(new MethodNode(method) { Context = Context }); yield break; } } }
private IEnumerable <AnalyzerTreeNode> FindReferencesInType(TypeDef type) { foreach (MethodDef method in type.Methods) { bool found = false; if (!method.HasBody) { continue; } // ignore chained constructors // (since object is the root of everything, we can short circuit the test in this case) if (method.Name == ".ctor" && (isSystemObject || analyzedType == type || TypesHierarchyHelpers.IsBaseType(analyzedType, type, false))) { continue; } foreach (Instruction instr in method.Body.Instructions) { IMethod mr = instr.Operand as IMethod; if (mr != null && !mr.IsField && mr.Name == ".ctor") { if (Helpers.IsReferencedBy(analyzedType, mr.DeclaringType)) { found = true; break; } } } Helpers.FreeMethodBody(method); if (found) { var node = new AnalyzedMethodTreeNode(method); node.Language = this.Language; yield return(node); } } }
IEnumerable <IAnalyzerTreeNodeData> FindReferencesInType(TypeDef type) { if (!type.HasInterfaces || analyzedMethod == null) { yield break; } var iff = type.Interfaces.FirstOrDefault(i => new SigComparer().Equals(i.Interface, analyzedMethod.DeclaringType)); ITypeDefOrRef implementedInterfaceRef = iff == null ? null : iff.Interface; if (implementedInterfaceRef == null) { yield break; } //TODO: Can we compare event types too? foreach (EventDef ev in type.Events.Where(e => e.Name == analyzedEvent.Name)) { MethodDef accessor = ev.AddMethod ?? ev.RemoveMethod; if (accessor != null && TypesHierarchyHelpers.MatchInterfaceMethod(accessor, analyzedMethod, implementedInterfaceRef)) { yield return(new EventNode(ev) { Context = Context }); } } foreach (EventDef ev in type.Events.Where(e => e.Name.EndsWith(analyzedEvent.Name))) { MethodDef accessor = ev.AddMethod ?? ev.RemoveMethod; if (accessor != null && accessor.HasOverrides && accessor.Overrides.Any(m => m.MethodDeclaration.ResolveMethodDef() == analyzedMethod)) { yield return(new EventNode(ev) { Context = Context }); } } }
private IEnumerable <SharpTreeNode> FindReferencesInType(TypeDefinition type) { foreach (MethodDefinition method in type.Methods) { bool found = false; if (!method.HasBody) { continue; } // ignore chained constructors // (since object is the root of everything, we can short circuit the test in this case) if (method.Name == ".ctor" && (isSystemObject || analyzedType == type || TypesHierarchyHelpers.IsBaseType(analyzedType, type, false))) { continue; } foreach (Instruction instr in method.Body.Instructions) { MethodReference mr = instr.Operand as MethodReference; if (mr != null && mr.Name == ".ctor") { if (Helpers.IsReferencedBy(analyzedType, mr.DeclaringType)) { found = true; break; } } } method.Body = null; if (found) { yield return(new AnalyzedMethodTreeNode(method)); } } }
IEnumerable <IAnalyzerTreeNodeData> FindReferencesInType(TypeDef type) { if (!type.HasInterfaces) { yield break; } var iff = type.Interfaces.FirstOrDefault(i => new SigComparer().Equals(i.Interface, analyzedMethod.DeclaringType)); ITypeDefOrRef implementedInterfaceRef = iff == null ? null : iff.Interface; if (implementedInterfaceRef == null) { yield break; } //TODO: Can we compare method sigs too? foreach (MethodDef method in type.Methods.Where(m => m.Name == analyzedMethod.Name)) { if (TypesHierarchyHelpers.MatchInterfaceMethod(method, analyzedMethod, implementedInterfaceRef)) { yield return(new MethodNode(method) { Context = Context }); } yield break; } foreach (MethodDef method in type.Methods) { if (method.HasOverrides && method.Overrides.Any(m => m.MethodDeclaration.ResolveMethodDef() == analyzedMethod)) { yield return(new MethodNode(method) { Context = Context }); } } }
public static IEnumerable <VirtualMethod> VirtualAnalysis(IEnumerable <TypeDefinition> types) { var virtuals = new Dictionary <MethodDefinition, VirtualMethod>(); foreach (var t in types) { foreach (var m in t.Methods) { //types var overrides = TypesHierarchyHelpers.FindBaseMethods(m).Where(b => b.IsVirtual); foreach (var basem in overrides) { AddMethod(virtuals, m, basem); } foreach (var i in t.Interfaces) { foreach (var interfaceMethod in i.InterfaceType.Resolve().Methods) { // don't create virtual for the instance checker metod if (interfaceMethod.Name.Contains("IsInstance")) { continue; } //if (MatchInterfaceMethod(interfaceMethod, m)) if (TypesHierarchyHelpers.MatchInterfaceMethod(interfaceMethod, m, i.InterfaceType)) { AddMethod(virtuals, m, interfaceMethod); } } } } } return(virtuals.Values.ToArray()); }
IEnumerable <SharpTreeNode> FindReferences(LoadedAssembly asm, CancellationToken ct) { string asmName = asm.AssemblyDefinition.Name.Name; string name = analyzedProperty.Name; string declTypeName = analyzedProperty.DeclaringType.FullName; foreach (TypeDefinition type in TreeTraversal.PreOrder(asm.AssemblyDefinition.MainModule.Types, t => t.NestedTypes)) { ct.ThrowIfCancellationRequested(); SharpTreeNode newNode = null; try { if (!TypesHierarchyHelpers.IsBaseType(analyzedProperty.DeclaringType, type, resolveTypeArguments: false)) { continue; } foreach (PropertyDefinition property in type.Properties) { ct.ThrowIfCancellationRequested(); if (TypesHierarchyHelpers.IsBaseProperty(analyzedProperty, property)) { MethodDefinition anyAccessor = property.GetMethod ?? property.SetMethod; bool hidesParent = !anyAccessor.IsVirtual ^ anyAccessor.IsNewSlot; newNode = new AnalyzedPropertyTreeNode(property, hidesParent ? "(hides) " : ""); } } } catch (ReferenceResolvingException) { // ignore this type definition. } if (newNode != null) { yield return(newNode); } } }
private IEnumerable <SharpTreeNode> FindReferences(LoadedAssembly asm, CancellationToken ct) { string asmName = asm.AssemblyDefinition.Name.Name; string name = analyzedMethod.Name; string declTypeName = analyzedMethod.DeclaringType.FullName; foreach (TypeDefinition type in TreeTraversal.PreOrder(asm.AssemblyDefinition.MainModule.Types, t => t.NestedTypes)) { ct.ThrowIfCancellationRequested(); SharpTreeNode newNode = null; try { if (!TypesHierarchyHelpers.IsBaseType(analyzedMethod.DeclaringType, type, resolveTypeArguments: false)) { continue; } foreach (MethodDefinition method in type.Methods) { ct.ThrowIfCancellationRequested(); if (TypesHierarchyHelpers.IsBaseMethod(analyzedMethod, method)) { bool hidesParent = !method.IsVirtual ^ method.IsNewSlot; newNode = new AnalyzedMethodTreeNode(method, hidesParent ? "(hides) " : ""); } } } catch (ReferenceResolvingException) { // ignore this type definition. maybe add a notification about such cases. } if (newNode != null) { yield return(newNode); } } }
private IEnumerable <AnalyzerTreeNode> FindReferencesInType(TypeDef type) { if (!type.HasInterfaces) { yield break; } ITypeDefOrRef implementedInterfaceRef = type.Interfaces.FirstOrDefault(i => i.Interface.ResolveTypeDef() == analyzedMethod.DeclaringType).Interface; if (implementedInterfaceRef == null) { yield break; } foreach (EventDef ev in type.Events.Where(e => e.Name == analyzedEvent.Name)) { MethodDef accessor = ev.AddMethod ?? ev.RemoveMethod; if (TypesHierarchyHelpers.MatchInterfaceMethod(accessor, analyzedMethod, implementedInterfaceRef)) { var node = new AnalyzedEventTreeNode(ev); node.Language = this.Language; yield return(node); } yield break; } foreach (EventDef ev in type.Events.Where(e => e.Name.String.EndsWith(analyzedEvent.Name))) { MethodDef accessor = ev.AddMethod ?? ev.RemoveMethod; if (accessor.HasOverrides && accessor.Overrides.Any(m => Decompiler.DnlibExtensions.Resolve(m.MethodDeclaration) == analyzedMethod)) { var node = new AnalyzedEventTreeNode(ev); node.Language = this.Language; yield return(node); } } }