internal static bool IsKnownType(this SyntaxNode syntaxNode, KnownType knownType, SemanticModel semanticModel)
        {
            var symbolType = semanticModel.GetSymbolInfo(syntaxNode).Symbol.GetSymbolType();

            return(symbolType.Is(knownType) || symbolType?.OriginalDefinition?.Is(knownType) == true);
        }
Beispiel #2
0
 public static IEnumerable <AttributeSyntax> GetAttributes(this SyntaxList <AttributeListSyntax> attributeLists,
                                                           KnownType attributeKnownType, SemanticModel semanticModel) =>
 GetAttributes(attributeLists, new HashSet <KnownType> {
     attributeKnownType
 }, semanticModel);
 public static bool Is(this ITypeSymbol typeSymbol, KnownType type)
 {
     return(typeSymbol != null && IsMatch(typeSymbol, type));
 }
 public static bool IsInType(this ISymbol symbol, KnownType type)
 {
     return(symbol != null && symbol.ContainingType.Is(type));
 }
Beispiel #5
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);
        }
 public static bool DerivesOrImplements(this ITypeSymbol type, KnownType baseType)
 {
     return(type.Implements(baseType) ||
            type.DerivesFrom(baseType));
 }
 internal static IEnumerable <ISymbol> GetSymbolsOfKnownType(this SeparatedSyntaxList <ArgumentSyntax> syntaxList, KnownType knownType, SemanticModel semanticModel) =>
 syntaxList
 .GetArgumentsOfKnownType(knownType, semanticModel)
 .Select(argument => semanticModel.GetSymbolInfo(argument.Expression).Symbol);
Beispiel #8
0
 internal static bool AnyAttributeDerivesFrom(this ISymbol symbol, KnownType attributeType) =>
 symbol?.GetAttributes().Any(a => a.AttributeClass.DerivesFrom(attributeType)) ?? false;
Beispiel #9
0
 internal MemberDescriptor(KnownType containingType, string name)
 {
     ContainingType = containingType;
     Name           = name;
 }
 internal static IEnumerable <ArgumentSyntax> GetArgumentsOfKnownType(this SeparatedSyntaxList <ArgumentSyntax> syntaxList, KnownType knownType, SemanticModel semanticModel) =>
 syntaxList
 .Where(argument => semanticModel.GetTypeInfo(argument.Expression).Type.Is(knownType));
Beispiel #11
0
 public static IEnumerable <ArgumentSyntax> GetArgumentsOfKnownType(this ObjectCreationExpressionSyntax objectCreation, KnownType knownType, SemanticModel semanticModel) =>
 objectCreation?.ArgumentList?.Arguments.GetArgumentsOfKnownType(knownType, semanticModel) ?? Enumerable.Empty <ArgumentSyntax>();
 internal static IEnumerable <ISymbol> GetArgumentSymbolsOfKnownType(this InvocationExpressionSyntax invocation, KnownType knownType, SemanticModel semanticModel) =>
 invocation.ArgumentList.Arguments.GetSymbolsOfKnownType(knownType, semanticModel);
Beispiel #13
0
 internal static bool HasAttribute(this ISymbol symbol, KnownType attributeType) =>
 symbol?.GetAttributes().Any(a => a.AttributeClass.Is(attributeType))
 ?? false;
 internal ObjectCreationCondition WhenDerivesFrom(KnownType baseType) =>
 (context) =>
 context.InvokedConstructorSymbol.Value != null &&
 context.InvokedConstructorSymbol.Value.IsConstructor() &&
 context.InvokedConstructorSymbol.Value.ContainingType.DerivesFrom(baseType);
        internal static bool IsKnownType(this SyntaxNode syntaxNode, KnownType knownType, SemanticModel semanticModel)
        {
            var symbolType = semanticModel.GetSymbolInfo(syntaxNode).Symbol.GetSymbolType();

            return(symbolType.Is(knownType));
        }
Beispiel #16
0
 internal static IEnumerable <AttributeData> GetAttributes(this ISymbol symbol, KnownType attributeType) =>
 symbol?.GetAttributes().Where(a => a.AttributeClass.Is(attributeType))
 ?? Enumerable.Empty <AttributeData>();
Beispiel #17
0
 internal static bool IsMemberAccessOnKnownType(this InvocationExpressionSyntax invocation, string identifierName, KnownType knownType, SemanticModel semanticModel) =>
 invocation.Expression is MemberAccessExpressionSyntax memberAccessExpressionSyntax &&
 public static bool HasAttribute(this ISymbol symbol, KnownType type) =>
 symbol.GetAttributes(type).Any();
Beispiel #19
0
 internal MethodSignature(KnownType containingType, string name)
 {
     ContainingType = containingType;
     Name           = name;
 }
 public static IEnumerable <AttributeSyntax> GetAttributes(this SyntaxList <AttributeListSyntax> attributeLists,
                                                           KnownType attributeKnownType, SemanticModel semanticModel) =>
 attributeLists.SelectMany(list => list.Attributes)
 .Where(a => semanticModel.GetTypeInfo(a).Type.Is(attributeKnownType));
 internal InvocationCondition ArgumentAtIndexIs(int index, KnownType requiredType) =>
 (context) =>
 context.MethodSymbol.Value != null &&
 context.MethodSymbol.Value.Parameters.Length > index &&
 context.MethodSymbol.Value.Parameters[index].IsType(requiredType);
 private static bool IsMatch(ITypeSymbol typeSymbol, KnownType type)
 {
     return(type.Matches(typeSymbol.SpecialType) || type.Matches(typeSymbol.ToDisplayString()));
 }
 internal InvocationCondition MethodReturnTypeIs(KnownType returnType) =>
 (context) =>
 context.MethodSymbol.Value != null &&
 context.MethodSymbol.Value.ReturnType.DerivesFrom(returnType);
 public static bool IsType(this IParameterSymbol parameter, KnownType type)
 {
     return(parameter != null && parameter.Type.Is(type));
 }
 public static bool IsMethodInvocation(this InvocationExpressionSyntax expression, KnownType type, string methodName, SemanticModel semanticModel) =>
 expression.NameIs(methodName) &&
 semanticModel.GetSymbolInfo(expression).Symbol is IMethodSymbol methodSymbol &&
 public static bool Implements(this ITypeSymbol typeSymbol, KnownType type)
 {
     return(typeSymbol != null &&
            typeSymbol.AllInterfaces.Any(symbol => symbol.ConstructedFrom.Is(type)));
 }
 internal ObjectCreationCondition ArgumentAtIndexIs(int index, KnownType type) =>
 (context) =>
 context.InvokedConstructorSymbol.Value != null &&
 context.InvokedConstructorSymbol.Value.Parameters.Length > index &&
 context.InvokedConstructorSymbol.Value.Parameters[index].Type.Is(type);
Beispiel #28
0
        internal static bool IsDeclarationKnownType(this SyntaxNode syntaxNode, KnownType knownType, SemanticModel semanticModel)
        {
            var symbolType = semanticModel.GetDeclaredSymbol(syntaxNode)?.GetSymbolType();

            return(symbolType.Is(knownType));
        }
Beispiel #29
0
 public static bool IsMemberAccessOnKnownType(this MemberAccessExpressionSyntax memberAccess, string name, KnownType knownType, SemanticModel semanticModel) =>
 memberAccess.NameIs(name) &&
 semanticModel.GetSymbolInfo(memberAccess).Symbol is
 {