예제 #1
0
        public static bool TryGetAttribute(this SyntaxList<AttributeListSyntax> attributeLists, KnownType attributeKnownType,
            SemanticModel semanticModel, out AttributeSyntax searchedAttribute)
        {
            searchedAttribute = null;

            if (!attributeLists.Any())
            {
                return false;
            }

            foreach (var attribute in attributeLists.SelectMany(attributeList => attributeList.Attributes))
            {
                var attributeType = semanticModel.GetTypeInfo(attribute).Type;

                if (attributeType.Is(attributeKnownType))
                {
                    searchedAttribute = attribute;
                    return true;
                }
            }

            return false;
        }
예제 #2
0
 public static bool Implements(this ITypeSymbol typeSymbol, KnownType type)
 {
     return typeSymbol != null &&
         typeSymbol.AllInterfaces.Any(symbol => symbol.ConstructedFrom.Is(type));
 }
예제 #3
0
 public static bool IsType(this IParameterSymbol parameter, KnownType type)
 {
     return parameter != null && parameter.Type.Is(type);
 }
예제 #4
0
 public static bool IsInType(this ISymbol symbol, KnownType type)
 {
     return symbol != null && symbol.ContainingType.Is(type);
 }
예제 #5
0
 private static bool IsMatch(ITypeSymbol typeSymbol, KnownType type)
 {
     return type.Matches(typeSymbol.SpecialType) || type.Matches(typeSymbol.ToDisplayString());
 }
예제 #6
0
 public static bool Is(this ITypeSymbol typeSymbol, KnownType type)
 {
     return typeSymbol != null && IsMatch(typeSymbol, type);
 }
예제 #7
0
        public static bool DerivesFrom(this ITypeSymbol typeSymbol, KnownType type)
        {
            var currentType = typeSymbol;
            while(currentType != null)
            {
                if (currentType.Is(type))
                {
                    return true;
                }
                currentType = currentType.BaseType;
            }

            return false;
        }
예제 #8
0
 public static bool DerivesOrImplements(this ITypeSymbol type, KnownType baseType)
 {
     return type.Implements(baseType) ||
         type.DerivesFrom(baseType);
 }
예제 #9
0
 public static bool IsInType(this ISymbol symbol, KnownType type)
 {
     return(symbol != null && symbol.ContainingType.Is(type));
 }
예제 #10
0
 public static bool Implements(this ITypeSymbol typeSymbol, KnownType type)
 {
     return(typeSymbol != null &&
            typeSymbol.AllInterfaces.Any(symbol => symbol.ConstructedFrom.Is(type)));
 }
예제 #11
0
 public static bool IsType(this IParameterSymbol parameter, KnownType type)
 {
     return(parameter != null && parameter.Type.Is(type));
 }
예제 #12
0
 public static bool Is(this ITypeSymbol typeSymbol, KnownType type)
 {
     return(typeSymbol != null && IsMatch(typeSymbol, type));
 }
예제 #13
0
 private static bool IsMatch(ITypeSymbol typeSymbol, KnownType type)
 {
     return(type.Matches(typeSymbol.SpecialType) || type.Matches(typeSymbol.ToDisplayString()));
 }
예제 #14
0
 public static bool DerivesOrImplements(this ITypeSymbol type, KnownType baseType)
 {
     return(type.Implements(baseType) ||
            type.DerivesFrom(baseType));
 }
        public static bool TryGetAttribute(this SyntaxList <AttributeListSyntax> attributeLists, KnownType attributeKnownType,
                                           SemanticModel semanticModel, out AttributeSyntax searchedAttribute)
        {
            searchedAttribute = null;

            if (!attributeLists.Any())
            {
                return(false);
            }

            foreach (var attribute in attributeLists.SelectMany(attributeList => attributeList.Attributes))
            {
                var attributeType = semanticModel.GetTypeInfo(attribute).Type;

                if (attributeType.Is(attributeKnownType))
                {
                    searchedAttribute = attribute;
                    return(true);
                }
            }

            return(false);
        }