Ejemplo n.º 1
0
        private IEnumerable <AnalyzerTreeNode> FindReferencesInType(TypeDefinition type)
        {
            if (analyzedType.IsEnum && type == analyzedType)
            {
                yield break;
            }

            if (!this.Language.ShowMember(type))
            {
                yield break;
            }

            foreach (FieldDefinition field in type.Fields)
            {
                if (TypeIsExposedBy(field))
                {
                    var node = new AnalyzedFieldTreeNode(field);
                    node.Language = this.Language;
                    yield return(node);
                }
            }

            foreach (PropertyDefinition property in type.Properties)
            {
                if (TypeIsExposedBy(property))
                {
                    var node = new AnalyzedPropertyTreeNode(property);
                    node.Language = this.Language;
                    yield return(node);
                }
            }

            foreach (EventDefinition eventDef in type.Events)
            {
                if (TypeIsExposedBy(eventDef))
                {
                    var node = new AnalyzedEventTreeNode(eventDef);
                    node.Language = this.Language;
                    yield return(node);
                }
            }

            foreach (MethodDefinition method in type.Methods)
            {
                if (TypeIsExposedBy(method))
                {
                    var node = new AnalyzedMethodTreeNode(method);
                    node.Language = this.Language;
                    yield return(node);
                }
            }
        }
Ejemplo n.º 2
0
        private IEnumerable <AnalyzerTreeNode> FindReferencesInType(TypeDefinition type)
        {
            if (!TypesHierarchyHelpers.IsBaseType(analyzedProperty.DeclaringType, type, resolveTypeArguments: false))
            {
                yield break;
            }

            foreach (PropertyDefinition property in type.Properties)
            {
                if (TypesHierarchyHelpers.IsBaseProperty(analyzedProperty, property))
                {
                    MethodDefinition 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);
                }
            }
        }
Ejemplo n.º 3
0
        public bool IsEnabled(TextViewContext context)
        {
            if (context.SelectedTreeNodes == null)
            {
                return(context.Reference != null && context.Reference.Reference is MemberReference);
            }
            foreach (IMemberTreeNode node in context.SelectedTreeNodes)
            {
                if (!(node.Member is TypeDefinition ||
                      node.Member is FieldDefinition ||
                      node.Member is MethodDefinition ||
                      AnalyzedPropertyTreeNode.CanShow(node.Member) ||
                      AnalyzedEventTreeNode.CanShow(node.Member)))
                {
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 4
0
        private IEnumerable <AnalyzerTreeNode> FindReferencesInType(TypeDefinition type)
        {
            if (!type.HasInterfaces)
            {
                yield break;
            }
            TypeReference implementedInterfaceRef = type.Interfaces.FirstOrDefault(i => i.InterfaceType.Resolve() == analyzedMethod.DeclaringType)?.InterfaceType;

            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))
                {
                    var node = new AnalyzedPropertyTreeNode(property);
                    node.Language = this.Language;
                    yield return(node);
                }
                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))
                {
                    var node = new AnalyzedPropertyTreeNode(property);
                    node.Language = this.Language;
                    yield return(node);
                }
            }
        }
Ejemplo n.º 5
0
        private IEnumerable <AnalyzerTreeNode> FindReferencesWithinInType(TypeDefinition type, TypeReference attrTypeRef)
        {
            bool searchRequired = (type.IsClass && usage.HasFlag(AttributeTargets.Class)) ||
                                  (type.IsEnum && usage.HasFlag(AttributeTargets.Enum)) ||
                                  (type.IsInterface && usage.HasFlag(AttributeTargets.Interface)) ||
                                  (type.IsValueType && usage.HasFlag(AttributeTargets.Struct));

            if (searchRequired)
            {
                if (type.HasCustomAttributes)
                {
                    foreach (var attribute in type.CustomAttributes)
                    {
                        if (attribute.AttributeType == attrTypeRef)
                        {
                            var node = new AnalyzedTypeTreeNode(type);
                            node.Language = this.Language;
                            yield return(node);

                            break;
                        }
                    }
                }
            }

            if ((this.usage & AttributeTargets.GenericParameter) != 0 && type.HasGenericParameters)
            {
                foreach (var parameter in type.GenericParameters)
                {
                    if (parameter.HasCustomAttributes)
                    {
                        foreach (var attribute in parameter.CustomAttributes)
                        {
                            if (attribute.AttributeType == attrTypeRef)
                            {
                                var node = new AnalyzedTypeTreeNode(type);
                                node.Language = this.Language;
                                yield return(node);

                                break;
                            }
                        }
                    }
                }
            }

            if ((this.usage & AttributeTargets.Field) != 0 && type.HasFields)
            {
                foreach (var field in type.Fields)
                {
                    if (field.HasCustomAttributes)
                    {
                        foreach (var attribute in field.CustomAttributes)
                        {
                            if (attribute.AttributeType == attrTypeRef)
                            {
                                var node = new AnalyzedFieldTreeNode(field);
                                node.Language = this.Language;
                                yield return(node);

                                break;
                            }
                        }
                    }
                }
            }

            if (((usage & AttributeTargets.Property) != 0) && type.HasProperties)
            {
                foreach (var property in type.Properties)
                {
                    if (property.HasCustomAttributes)
                    {
                        foreach (var attribute in property.CustomAttributes)
                        {
                            if (attribute.AttributeType == attrTypeRef)
                            {
                                var node = new AnalyzedPropertyTreeNode(property);
                                node.Language = this.Language;
                                yield return(node);

                                break;
                            }
                        }
                    }
                }
            }
            if (((usage & AttributeTargets.Event) != 0) && type.HasEvents)
            {
                foreach (var _event in type.Events)
                {
                    if (_event.HasCustomAttributes)
                    {
                        foreach (var attribute in _event.CustomAttributes)
                        {
                            if (attribute.AttributeType == attrTypeRef)
                            {
                                var node = new AnalyzedEventTreeNode(_event);
                                node.Language = this.Language;
                                yield return(node);

                                break;
                            }
                        }
                    }
                }
            }

            if (type.HasMethods)
            {
                foreach (var method in type.Methods)
                {
                    bool found = false;
                    if ((usage & (AttributeTargets.Method | AttributeTargets.Constructor)) != 0)
                    {
                        if (method.HasCustomAttributes)
                        {
                            foreach (var attribute in method.CustomAttributes)
                            {
                                if (attribute.AttributeType == attrTypeRef)
                                {
                                    found = true;
                                    break;
                                }
                            }
                        }
                    }
                    if (!found &&
                        ((usage & AttributeTargets.ReturnValue) != 0) &&
                        method.MethodReturnType.HasCustomAttributes)
                    {
                        foreach (var attribute in method.MethodReturnType.CustomAttributes)
                        {
                            if (attribute.AttributeType == attrTypeRef)
                            {
                                found = true;
                                break;
                            }
                        }
                    }

                    if (!found &&
                        ((usage & AttributeTargets.Parameter) != 0) &&
                        method.HasParameters)
                    {
                        foreach (var parameter in method.Parameters)
                        {
                            foreach (var attribute in parameter.CustomAttributes)
                            {
                                if (attribute.AttributeType == attrTypeRef)
                                {
                                    found = true;
                                    break;
                                }
                            }
                        }
                    }

                    if (found)
                    {
                        MethodDefinition codeLocation = this.Language.GetOriginalCodeLocation(method) as MethodDefinition;
                        if (codeLocation != null && !HasAlreadyBeenFound(codeLocation))
                        {
                            var node = new AnalyzedMethodTreeNode(codeLocation);
                            node.Language = this.Language;
                            yield return(node);
                        }
                    }
                }
            }
        }