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 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 #3
0
 bool IsAssignableTo(TypeDefinition from, TypeDefinition to)
 {
     if (to.IsInterface)
     {
         return(from.Interfaces.Any(x => x.InterfaceType == to));
     }
     else
     {
         return(TypesHierarchyHelpers.IsBaseType(to, from, false));
     }
 }
Exemple #4
0
        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;
                }
            }
        }
Exemple #5
0
        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)
        {
            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)
        {
            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)
                           }
                }
                ;
            }
        }
        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 <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);
                }
            }
        }
        IEnumerable <IAnalyzerTreeNodeData> FindReferencesInType(TypeDef type)
        {
            if (!TypesHierarchyHelpers.IsBaseType(analyzedEvent.DeclaringType, type, resolveTypeArguments: false))
            {
                yield break;
            }

            foreach (EventDef eventDef in type.Events)
            {
                if (TypesHierarchyHelpers.IsBaseEvent(analyzedEvent, eventDef))
                {
                    MethodDef anyAccessor = eventDef.AddMethod ?? eventDef.RemoveMethod;
                    if (anyAccessor == null)
                    {
                        continue;
                    }
                    bool hidesParent = !anyAccessor.IsVirtual ^ anyAccessor.IsNewSlot;
                    yield return(new EventNode(eventDef, hidesParent)
                    {
                        Context = Context
                    });
                }
            }
        }
Exemple #12
0
        IEnumerable <AnalyzerTreeNodeData> 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;
                    if (anyAccessor == null)
                    {
                        continue;
                    }
                    bool hidesParent = !anyAccessor.IsVirtual ^ anyAccessor.IsNewSlot;
                    yield return(new PropertyNode(property, hidesParent)
                    {
                        Context = Context
                    });
                }
            }
        }