Exemple #1
0
        private static bool TryGetFix(
            SemanticModel semanticModel,
            CancellationToken cancellationToken,
            AssignmentExpressionSyntax assignment,
            out InvocationExpressionSyntax setCurrentValueInvocation)
        {
            setCurrentValueInvocation = null;
            if (!SetCurrentValueExpression.TryCreate(assignment, out var setCurrentValue))
            {
                return(false);
            }

            if (!Arguments.TryCreateProperty(assignment, semanticModel, cancellationToken, out var property))
            {
                return(false);
            }

            if (!Arguments.TryCreateValue(assignment, semanticModel, cancellationToken, out var value))
            {
                return(false);
            }

            setCurrentValueInvocation = SyntaxFactory.InvocationExpression(
                setCurrentValue,
                SyntaxFactory.ArgumentList()
                .AddArguments(property, value))
                                        .WithLeadingTrivia(assignment.GetLeadingTrivia());
            return(true);
        }
Exemple #2
0
        private static bool TryGetFix(
            SemanticModel semanticModel,
            CancellationToken cancellationToken,
            InvocationExpressionSyntax setValue,
            out InvocationExpressionSyntax setCurrentValueInvocation)
        {
            setCurrentValueInvocation = null;
            if (!DependencyObject.TryGetSetValueArguments(
                    setValue,
                    semanticModel,
                    cancellationToken,
                    out ArgumentSyntax _,
                    out IFieldSymbol _,
                    out ArgumentSyntax _))
            {
                return(false);
            }

            if (SetCurrentValueExpression.TryCreate(setValue, out ExpressionSyntax setCurrentValue))
            {
                setCurrentValueInvocation = setValue.WithExpression(setCurrentValue)
                                            .WithLeadingTrivia(setValue.GetLeadingTrivia());
                return(true);
            }

            return(false);
        }