示例#1
0
            public override bool IsMatch(AttributeInfo attributeInfo)
            {
                INamedTypeSymbol attributeClass = attributeInfo.AttributeClass;

                if (AttributeNames.Contains(attributeClass))
                {
                    return(false);
                }

                ISymbol symbol = attributeInfo.Target;

                if (symbol.IsKind(SymbolKind.NamedType) &&
                    attributeClass.HasMetadataName(_defaultMemberAttribute))
                {
                    var namedType = (INamedTypeSymbol)symbol;

                    if (namedType.GetMembers().Any(f => f.IsKind(SymbolKind.Property) && ((IPropertySymbol)f).IsIndexer))
                    {
                        return(false);
                    }
                }
#if DEBUG
                Debug.Assert(
                    attributeClass.MetadataName == "FooAttribute" ||
                    attributeClass.MetadataName == "BarAttribute" ||
                    _knownVisibleAttributes.Contains(attributeClass),
                    attributeClass.ToDisplayString());
#endif
                return(true);
            }
示例#2
0
        public override SymbolFilterReason GetReason(ISymbol symbol, AttributeData attribute)
        {
            SymbolFilterReason reason = base.GetReason(symbol, attribute);

            if (reason != SymbolFilterReason.None)
            {
                return(reason);
            }

            if (symbol.IsKind(SymbolKind.NamedType) &&
                attribute.AttributeClass.HasMetadataName(_defaultMemberAttribute))
            {
                var namedType = (INamedTypeSymbol)symbol;

                if (namedType.GetMembers().Any(f => f.IsKind(SymbolKind.Property) && ((IPropertySymbol)f).IsIndexer))
                {
                    return(SymbolFilterReason.Ignored);
                }
            }

#if DEBUG
            switch (attribute.AttributeClass.MetadataName)
            {
            case "FooAttribute":
            case "BarAttribute":
                return(SymbolFilterReason.None);
            }

            if (_knownVisibleAttributes.Contains(attribute.AttributeClass))
            {
                return(SymbolFilterReason.None);
            }

            Debug.Fail(attribute.AttributeClass.ToDisplayString());
#endif
            return(reason);
        }