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;
        }
 public static bool IsInType(this ISymbol symbol, KnownType type)
 {
     return symbol != null && symbol.ContainingType.Is(type);
 }
 public static bool Implements(this ITypeSymbol typeSymbol, KnownType type)
 {
     return typeSymbol != null &&
         typeSymbol.AllInterfaces.Any(symbol => symbol.ConstructedFrom.Is(type));
 }
 public static bool IsType(this IParameterSymbol parameter, KnownType type)
 {
     return parameter != null && parameter.Type.Is(type);
 }
 public static bool Is(this ITypeSymbol typeSymbol, KnownType type)
 {
     return typeSymbol != null && IsMatch(typeSymbol, type);
 }
 private static bool IsMatch(ITypeSymbol typeSymbol, KnownType type)
 {
     return type.Matches(typeSymbol.SpecialType) || type.Matches(typeSymbol.ToDisplayString());
 }
 public static bool DerivesOrImplements(this ITypeSymbol type, KnownType baseType)
 {
     return type.Implements(baseType) ||
         type.DerivesFrom(baseType);
 }
        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;
        }