Exemplo n.º 1
0
        private static ConversionOperatorDeclarationSyntax UseExpressionBodyIfDesired(
            CodeGenerationOptions options,
            ConversionOperatorDeclarationSyntax declaration,
            ParseOptions parseOptions
            )
        {
            if (declaration.ExpressionBody == null)
            {
                var expressionBodyPreference =
                    options.Options.GetOption(
                        CSharpCodeStyleOptions.PreferExpressionBodiedOperators
                        ).Value;

                if (
                    declaration.Body.TryConvertToArrowExpressionBody(
                        declaration.Kind(),
                        parseOptions,
                        expressionBodyPreference,
                        out var expressionBody,
                        out var semicolonToken
                        )
                    )
                {
                    return(declaration
                           .WithBody(null)
                           .WithExpressionBody(expressionBody)
                           .WithSemicolonToken(semicolonToken));
                }
            }

            return(declaration);
        }
Exemplo n.º 2
0
        private static ConversionOperatorDeclarationSyntax UseExpressionBodyIfDesired(
            CSharpCodeGenerationOptions options, ConversionOperatorDeclarationSyntax declaration)
        {
            if (declaration.ExpressionBody == null)
            {
                if (declaration.Body?.TryConvertToArrowExpressionBody(
                        declaration.Kind(), options.Preferences.LanguageVersion, options.Preferences.PreferExpressionBodiedOperators,
                        out var expressionBody, out var semicolonToken) == true)
                {
                    return(declaration.WithBody(null)
                           .WithExpressionBody(expressionBody)
                           .WithSemicolonToken(semicolonToken));
                }
            }

            return(declaration);
        }