Пример #1
0
        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);
        }
Пример #2
0
 public static IEnumerable <AttributeSyntax> GetAttributes(this SyntaxList <AttributeListSyntax> attributeLists,
                                                           KnownType attributeKnownType, SemanticModel semanticModel) =>
 GetAttributes(attributeLists, new HashSet <KnownType> {
     attributeKnownType
 }, semanticModel);
Пример #3
0
 public static bool Is(this ITypeSymbol typeSymbol, KnownType type)
 {
     return(typeSymbol != null && IsMatch(typeSymbol, type));
 }
Пример #4
0
 public static bool IsInType(this ISymbol symbol, KnownType type)
 {
     return(symbol != null && symbol.ContainingType.Is(type));
 }
Пример #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);
        }
Пример #6
0
 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);
Пример #8
0
 internal static bool AnyAttributeDerivesFrom(this ISymbol symbol, KnownType attributeType) =>
 symbol?.GetAttributes().Any(a => a.AttributeClass.DerivesFrom(attributeType)) ?? false;
Пример #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));
Пример #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);
Пример #13
0
 internal static bool HasAttribute(this ISymbol symbol, KnownType attributeType) =>
 symbol?.GetAttributes().Any(a => a.AttributeClass.Is(attributeType))
 ?? false;
Пример #14
0
 internal ObjectCreationCondition WhenDerivesFrom(KnownType baseType) =>
 (context) =>
 context.InvokedConstructorSymbol.Value != null &&
 context.InvokedConstructorSymbol.Value.IsConstructor() &&
 context.InvokedConstructorSymbol.Value.ContainingType.DerivesFrom(baseType);
Пример #15
0
        internal static bool IsKnownType(this SyntaxNode syntaxNode, KnownType knownType, SemanticModel semanticModel)
        {
            var symbolType = semanticModel.GetSymbolInfo(syntaxNode).Symbol.GetSymbolType();

            return(symbolType.Is(knownType));
        }
Пример #16
0
 internal static IEnumerable <AttributeData> GetAttributes(this ISymbol symbol, KnownType attributeType) =>
 symbol?.GetAttributes().Where(a => a.AttributeClass.Is(attributeType))
 ?? Enumerable.Empty <AttributeData>();
Пример #17
0
 internal static bool IsMemberAccessOnKnownType(this InvocationExpressionSyntax invocation, string identifierName, KnownType knownType, SemanticModel semanticModel) =>
 invocation.Expression is MemberAccessExpressionSyntax memberAccessExpressionSyntax &&
Пример #18
0
 public static bool HasAttribute(this ISymbol symbol, KnownType type) =>
 symbol.GetAttributes(type).Any();
Пример #19
0
 internal MethodSignature(KnownType containingType, string name)
 {
     ContainingType = containingType;
     Name           = name;
 }
Пример #20
0
 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));
Пример #21
0
 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);
Пример #22
0
 private static bool IsMatch(ITypeSymbol typeSymbol, KnownType type)
 {
     return(type.Matches(typeSymbol.SpecialType) || type.Matches(typeSymbol.ToDisplayString()));
 }
Пример #23
0
 internal InvocationCondition MethodReturnTypeIs(KnownType returnType) =>
 (context) =>
 context.MethodSymbol.Value != null &&
 context.MethodSymbol.Value.ReturnType.DerivesFrom(returnType);
Пример #24
0
 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 &&
Пример #26
0
 public static bool Implements(this ITypeSymbol typeSymbol, KnownType type)
 {
     return(typeSymbol != null &&
            typeSymbol.AllInterfaces.Any(symbol => symbol.ConstructedFrom.Is(type)));
 }
Пример #27
0
 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);
Пример #28
0
        internal static bool IsDeclarationKnownType(this SyntaxNode syntaxNode, KnownType knownType, SemanticModel semanticModel)
        {
            var symbolType = semanticModel.GetDeclaredSymbol(syntaxNode)?.GetSymbolType();

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