Beispiel #1
0
        private static int?GetConstantArgumentValue(ArgumentSyntax argument, SemanticModel semanticModel)
        {
            var bound = semanticModel.GetConstantValue(argument.GetExpression());

            if (!bound.HasValue)
            {
                return(null);
            }

            var boundValue = bound.Value as int?;

            return(boundValue);
        }
        private static SeparatedSyntaxList <ArgumentSyntax> BuildNewMustHaveHappenedArgumentsFromRepeated(ArgumentSyntax repeatedNode)
        {
            // The original argument was Repeated.<comparisonType>.Times.
            var comparisonType = GetComparisonType(repeatedNode);

            // Fetch the repeated nodes's expression, which will be the Times call, and grab its argument for MustHaveHappened.
            // This is the call count specified in the assertion.
            var timesArgumentList = ((InvocationExpressionSyntax)repeatedNode.GetExpression()).ArgumentList;

            return(SeparatedList <ArgumentSyntax>(new SyntaxNodeOrToken[]
            {
                timesArgumentList.Arguments[0],
                Token(SyntaxKind.CommaToken),
                Argument(SimpleMemberAccess(IdentifierName("Times"), IdentifierName(comparisonType)))
            }));
        }
Beispiel #3
0
        private static bool IsValidGetter(ArgumentSyntax argument, SemanticModel semanticModel, INamedTypeSymbol containingType, out IPropertySymbol propertySymbol, out SimpleNameSyntax nameSyntax)
        {
            propertySymbol = null;
            nameSyntax     = null;

            var expression = argument.GetExpression();

            if (!(expression is SingleLineLambdaExpressionSyntax lambdaExpression))
            {
                return(false);
            }

            if (!(lambdaExpression.Body is MemberAccessExpressionSyntax memberAccessExpression))
            {
                return(false);
            }

            if (!memberAccessExpression.IsKind(SyntaxKind.SimpleMemberAccessExpression))
            {
                return(false);
            }

            if (!(semanticModel.GetSymbolInfo(memberAccessExpression).Symbol is IPropertySymbol result))
            {
                return(false);
            }

            if (result.ContainingType != containingType)
            {
                return(false);
            }

            if (result.SetMethod == null)
            {
                return(false);
            }

            propertySymbol = result;
            nameSyntax     = memberAccessExpression.Name;
            return(true);
        }
        private static int? GetConstantArgumentValue(ArgumentSyntax argument, SemanticModel semanticModel)
        {
            var bound = semanticModel.GetConstantValue(argument.GetExpression());
            if (!bound.HasValue)
            {
                return null;
            }

            var boundValue = bound.Value as int?;
            return boundValue;
        }
 private static string GetTypeName(SyntaxNodeAnalysisContext context, ArgumentSyntax argument)
 {
     return(context.SemanticModel.GetTypeInfo(argument.GetExpression()).ConvertedType?.ToString());
 }