Esempio n. 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;
        }
Esempio n. 2
0
 public static bool Implements(this ITypeSymbol typeSymbol, KnownType type)
 {
     return typeSymbol != null &&
         typeSymbol.AllInterfaces.Any(symbol => symbol.ConstructedFrom.Is(type));
 }
Esempio n. 3
0
 public static bool IsType(this IParameterSymbol parameter, KnownType type)
 {
     return parameter != null && parameter.Type.Is(type);
 }
Esempio n. 4
0
 public static bool IsInType(this ISymbol symbol, KnownType type)
 {
     return symbol != null && symbol.ContainingType.Is(type);
 }
Esempio n. 5
0
 private static bool IsMatch(ITypeSymbol typeSymbol, KnownType type)
 {
     return type.Matches(typeSymbol.SpecialType) || type.Matches(typeSymbol.ToDisplayString());
 }
Esempio n. 6
0
 public static bool Is(this ITypeSymbol typeSymbol, KnownType type)
 {
     return typeSymbol != null && IsMatch(typeSymbol, type);
 }
Esempio n. 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;
        }
Esempio n. 8
0
 public static bool DerivesOrImplements(this ITypeSymbol type, KnownType baseType)
 {
     return type.Implements(baseType) ||
         type.DerivesFrom(baseType);
 }
Esempio n. 9
0
 public static bool IsInType(this ISymbol symbol, KnownType type)
 {
     return(symbol != null && symbol.ContainingType.Is(type));
 }
Esempio n. 10
0
 public static bool Implements(this ITypeSymbol typeSymbol, KnownType type)
 {
     return(typeSymbol != null &&
            typeSymbol.AllInterfaces.Any(symbol => symbol.ConstructedFrom.Is(type)));
 }
Esempio n. 11
0
 public static bool IsType(this IParameterSymbol parameter, KnownType type)
 {
     return(parameter != null && parameter.Type.Is(type));
 }
Esempio n. 12
0
 public static bool Is(this ITypeSymbol typeSymbol, KnownType type)
 {
     return(typeSymbol != null && IsMatch(typeSymbol, type));
 }
Esempio n. 13
0
 private static bool IsMatch(ITypeSymbol typeSymbol, KnownType type)
 {
     return(type.Matches(typeSymbol.SpecialType) || type.Matches(typeSymbol.ToDisplayString()));
 }
Esempio n. 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);
        }