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);
            }
        }
Exemple #2
0
        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);
            }
        }
        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);
                }
            }
        }
Exemple #4
0
        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 method in type.Methods)
                    {
                        if (TypesHierarchyHelpers.IsBaseMethod(method, analyzedMethod))
                        {
                            yield return(new MethodNode(method)
                            {
                                Context = Context
                            });

                            yield break;
                        }
                    }
                    type = type.BaseType.ResolveTypeDef();
                }
            }
        }