当前位置: 首页>>代码示例>>C#>>正文


C# SyntaxGenerator.MemberAccessExpression方法代码示例

本文整理汇总了C#中SyntaxGenerator.MemberAccessExpression方法的典型用法代码示例。如果您正苦于以下问题:C# SyntaxGenerator.MemberAccessExpression方法的具体用法?C# SyntaxGenerator.MemberAccessExpression怎么用?C# SyntaxGenerator.MemberAccessExpression使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SyntaxGenerator的用法示例。


在下文中一共展示了SyntaxGenerator.MemberAccessExpression方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateOrdinalMemberAccess

 internal SyntaxNode CreateOrdinalMemberAccess(SyntaxGenerator syntaxFactoryService, SemanticModel model)
 {
     var stringComparisonType = WellKnownTypes.StringComparison(model.Compilation);
     return syntaxFactoryService.MemberAccessExpression(
         syntaxFactoryService.TypeExpression(stringComparisonType),
         syntaxFactoryService.IdentifierName(CA1309DiagnosticAnalyzer.OrdinalText));
 }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:7,代码来源:CA1309CodeFixProviderBase.cs

示例2: CreateEqualsExpression

        internal SyntaxNode CreateEqualsExpression(SyntaxGenerator syntaxFactoryService, SemanticModel model, SyntaxNode operand1, SyntaxNode operand2, bool isEquals)
        {
            var stringType = model.Compilation.GetSpecialType(SpecialType.System_String);
            var memberAccess = syntaxFactoryService.MemberAccessExpression(
                        syntaxFactoryService.TypeExpression(stringType),
                        syntaxFactoryService.IdentifierName(UseOrdinalStringComparisonAnalyzer.EqualsMethodName));
            var ordinal = CreateOrdinalMemberAccess(syntaxFactoryService, model);
            var invocation = syntaxFactoryService.InvocationExpression(
                memberAccess,
                operand1,
                operand2.WithoutTrailingTrivia(),
                ordinal)
                .WithAdditionalAnnotations(Formatter.Annotation);
            if (!isEquals)
            {
                invocation = syntaxFactoryService.LogicalNotExpression(invocation);
            }

            invocation = invocation.WithTrailingTrivia(operand2.GetTrailingTrivia());

            return invocation;
        }
开发者ID:maggiemsft,项目名称:roslyn-analyzers,代码行数:22,代码来源:UseOrdinalStringComparison.Fixer.cs

示例3: KeywordHelper

            internal static SyntaxNode KeywordHelper(SyntaxGenerator generator, BlockSyntax methodBlock)
            {
                var firstStatement = methodBlock.Statements[0] as LocalDeclarationStatementSyntax;
                var variableName = generator.IdentifierName(firstStatement.Declaration.Variables[0].Identifier.ValueText);
                var initializer = generator.MemberAccessExpression(variableName, "IfKeyword");
                var ifKeyword = generator.LocalDeclarationStatement("ifKeyword", initializer);

                return ifKeyword;
            }
开发者ID:tmeschter,项目名称:roslyn-analyzers-1,代码行数:9,代码来源:CodeFixProvider.cs

示例4: CreateCharSetArgument

 internal SyntaxNode CreateCharSetArgument(SyntaxGenerator syntaxFactoryService, INamedTypeSymbol charSetType)
 {
     return syntaxFactoryService.MemberAccessExpression(
         syntaxFactoryService.TypeExpression(charSetType), syntaxFactoryService.IdentifierName(UnicodeText));
 }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:5,代码来源:CA2101CodeFixProviderBase.cs

示例5: IfHelper

            internal static SyntaxNode IfHelper(SyntaxGenerator generator, string name)
            {
                var type = SyntaxFactory.ParseTypeName("IfStatementSyntax");
                var expression = generator.IdentifierName(name);
                var memberAccessExpression = generator.MemberAccessExpression(expression, "Node");
                var initializer = generator.CastExpression(type, memberAccessExpression);
                var ifStatement = generator.LocalDeclarationStatement("ifStatement", initializer);

                return ifStatement;
            }
开发者ID:tmeschter,项目名称:roslyn-analyzers-1,代码行数:10,代码来源:CodeFixProvider.cs

示例6: CreateEndOrStartSpan

            //creates an end or start span statement
            internal static SyntaxNode CreateEndOrStartSpan(SyntaxGenerator generator, string identifierString, string variableName)
            {
                SyntaxNode identifier = generator.IdentifierName(identifierString);

                SyntaxNode initializer = generator.MemberAccessExpression(identifier, "SpanStart");

                SyntaxNode localDeclaration = generator.LocalDeclarationStatement(variableName, initializer);

                return localDeclaration;
            }
开发者ID:tmeschter,项目名称:roslyn-analyzers-1,代码行数:11,代码来源:CodeFixProvider.cs

示例7: CreateDiagnostic

            internal static SyntaxNode CreateDiagnostic(SyntaxGenerator generator, string locationName, string ruleName)
            {
                var identifier = generator.IdentifierName("Diagnostic");
                var expression = generator.MemberAccessExpression(identifier, "Create");

                SyntaxList<SyntaxNode> arguments = new SyntaxList<SyntaxNode>();

                var ruleExpression = generator.IdentifierName(ruleName);
                var ruleArg = generator.Argument(ruleExpression);

                var locationExpression = generator.IdentifierName(locationName);
                var locationArg = generator.Argument(locationExpression);

                arguments = arguments.Add(ruleArg);
                arguments = arguments.Add(locationArg);

                string name = "diagnostic";
                var initializer = generator.InvocationExpression(expression, arguments);
                SyntaxNode localDeclaration = generator.LocalDeclarationStatement(name, initializer);

                return localDeclaration;
            }
开发者ID:tmeschter,项目名称:roslyn-analyzers-1,代码行数:22,代码来源:CodeFixProvider.cs

示例8: TriviaKindCheckHelper

            internal static SyntaxNode TriviaKindCheckHelper(SyntaxGenerator generator, IfStatementSyntax ifStatement, SyntaxList<SyntaxNode> ifBlockStatements)
            {
                var ifOneBlock = ifStatement.Statement as BlockSyntax;

                var trailingTriviaDeclaration = ifOneBlock.Statements[0] as LocalDeclarationStatementSyntax;
                var trailingTrivia = generator.IdentifierName(trailingTriviaDeclaration.Declaration.Variables[0].Identifier.ValueText);
                var arguments = new SyntaxList<SyntaxNode>();
                var trailingTriviaKind = generator.InvocationExpression(generator.MemberAccessExpression(trailingTrivia, "Kind"), arguments);

                var whitespaceTrivia = generator.MemberAccessExpression(generator.IdentifierName("SyntaxKind"), "WhitespaceTrivia");

                var equalsExpression = generator.ValueEqualsExpression(trailingTriviaKind, whitespaceTrivia);

                var newIfStatement = generator.IfStatement(equalsExpression, ifBlockStatements);

                return newIfStatement;
            }
开发者ID:tmeschter,项目名称:roslyn-analyzers-1,代码行数:17,代码来源:CodeFixProvider.cs

示例9: CreateLocation

            //creates the diagnostic location statement
            internal static SyntaxNode CreateLocation(SyntaxGenerator generator, string ifStatementIdentifier, string spanIdentifier)
            {
                string name = "diagnosticLocation";
                SyntaxNode memberIdentifier = generator.IdentifierName("Location");
                SyntaxNode memberName = generator.IdentifierName("Create");
                SyntaxNode expression = generator.MemberAccessExpression(memberIdentifier, memberName);

                SyntaxList<SyntaxNode> arguments = new SyntaxList<SyntaxNode>();

                var treeIdentifier = generator.IdentifierName(ifStatementIdentifier);
                var treeArgExpression = generator.MemberAccessExpression(treeIdentifier, "SyntaxTree");
                var treeArg = generator.Argument(treeArgExpression);

                var spanArgIdentifier = generator.IdentifierName(spanIdentifier);
                var spanArg = generator.Argument(spanArgIdentifier);

                arguments = arguments.Add(treeArg);
                arguments = arguments.Add(spanArg);

                SyntaxNode initializer = generator.InvocationExpression(expression, arguments);
                SyntaxNode localDeclaration = generator.LocalDeclarationStatement(name, initializer);

                return localDeclaration;
            }
开发者ID:tmeschter,项目名称:roslyn-analyzers-1,代码行数:25,代码来源:CodeFixProvider.cs

示例10: TriviaCheckHelper

            // creates the HasTrailingTrivia check
            protected internal static SyntaxNode TriviaCheckHelper(SyntaxGenerator generator, BlockSyntax methodBlock, SyntaxList<StatementSyntax> ifBlockStatements)
            {
                string variableName = GetIfKeywordName(methodBlock);
                SyntaxNode identifierName = generator.IdentifierName(variableName);
                SyntaxNode conditional = generator.MemberAccessExpression(identifierName, "HasTrailingTrivia");
                SyntaxNode ifStatement = generator.IfStatement(conditional, ifBlockStatements);

                return ifStatement;
            }
开发者ID:maggiemsft,项目名称:roslyn-analyzers,代码行数:10,代码来源:CodeFixProvider.cs

示例11: TriviaVarMissingHelper

            // creates the first trailing trivia variable
            protected internal static SyntaxNode TriviaVarMissingHelper(SyntaxGenerator generator, IfStatementSyntax declaration)
            {
                var methodDecl = declaration.Parent.AncestorsAndSelf().OfType<MethodDeclarationSyntax>().First();
                var methodBlock = methodDecl.Body as BlockSyntax;

                string variableName = GetIfKeywordName(methodBlock);
                SyntaxNode identifierName = generator.IdentifierName(variableName);

                SyntaxNode ifTrailing = generator.MemberAccessExpression(identifierName, "TrailingTrivia");
                SyntaxNode fullVariable = generator.MemberAccessExpression(ifTrailing, "First");
                var parameters = new SyntaxList<SyntaxNode>();
                SyntaxNode variableExpression = generator.InvocationExpression(fullVariable, parameters);
                SyntaxNode localDeclaration = generator.LocalDeclarationStatement("trailingTrivia", variableExpression);

                return localDeclaration;
            }
开发者ID:maggiemsft,项目名称:roslyn-analyzers,代码行数:17,代码来源:CodeFixProvider.cs

示例12: BuildRegister

 // builds a register statement
 protected internal static SyntaxNode BuildRegister(SyntaxGenerator generator, string context, string register, ArgumentListSyntax argumentList)
 {
     SyntaxNode registerIdentifier = generator.IdentifierName(register);
     SyntaxNode contextIdentifier = generator.IdentifierName(context);
     SyntaxNode memberExpr = generator.MemberAccessExpression(contextIdentifier, registerIdentifier);
     SyntaxNode invocationExpr = generator.InvocationExpression(memberExpr, argumentList.Arguments);
     return invocationExpr;
 }
开发者ID:maggiemsft,项目名称:roslyn-analyzers,代码行数:9,代码来源:CodeFixProvider.cs

示例13: KeywordHelper

            // creates the if-keyword statement
            protected internal static SyntaxNode KeywordHelper(SyntaxGenerator generator, BlockSyntax methodBlock)
            {
                string variableName = GetIfStatementName(methodBlock);
                SyntaxNode identifierName = generator.IdentifierName(variableName);
                SyntaxNode initializer = generator.MemberAccessExpression(identifierName, "IfKeyword");
                SyntaxNode ifKeyword = generator.LocalDeclarationStatement("ifKeyword", initializer);

                return ifKeyword;
            }
开发者ID:maggiemsft,项目名称:roslyn-analyzers,代码行数:10,代码来源:CodeFixProvider.cs

示例14: GetMethodStatementsSyntax

        private static IEnumerable<SyntaxNode> GetMethodStatementsSyntax(
            SyntaxGenerator syntaxGenerator,
            SemanticModel semanticModel,
            IMethodSymbol methodSymbol)
        {
            // GENERATED CODE (for every ref or out parameter):
            //
            //     string someOutParameter;
            //     var someRefParameter = default(int);
            for (var i = 0; i < methodSymbol.Parameters.Length; ++i)
            {
                var parameter = methodSymbol.Parameters[i];

                if (parameter.RefKind == RefKind.Out)
                {
                    yield return syntaxGenerator
                        .LocalDeclarationStatement(
                            syntaxGenerator.TypeExpression(parameter.Type),
                            GetNameForParameter(methodSymbol, parameter));
                }
                else if (parameter.RefKind == RefKind.Ref)
                {
                    yield return syntaxGenerator
                        .LocalDeclarationStatement(
                            GetNameForParameter(methodSymbol, parameter),
                            initializer: syntaxGenerator.DefaultExpression(syntaxGenerator.TypeExpression(parameter.Type)));
                }
            }

            var arguments = methodSymbol
                .Parameters
                .Select(x =>
                    syntaxGenerator
                        .Argument(
                            x.RefKind,
                            syntaxGenerator.IdentifierName(GetNameForParameter(methodSymbol, x))))
                .ToList();

            var typeArguments = methodSymbol
                .TypeArguments
                .Select(x => syntaxGenerator.TypeExpression(x))
                .ToList();

            var lambdaParameterName = GetUniqueName(methodSymbol);

            var lambdaInvocation = syntaxGenerator
                .MemberAccessExpression(
                    syntaxGenerator.IdentifierName(lambdaParameterName),
                    methodSymbol.Name);

            if (typeArguments.Count > 0)
            {
                lambdaInvocation = syntaxGenerator
                    .WithTypeArguments(
                        lambdaInvocation,
                        typeArguments);
            }

            // GENERATED CODE (for every ref or out parameter):
            //
            //     someOutParameter = this.GetOutParameterValue<string>(x => x.TheMethod(out someOutParameter), parameterIndex: 0);
            //     someRefParameter = this.GetRefParameterValue<int>(x => x.TheMethod(ref someRefParameter), parameterIndex: 0);
            for (var i = 0; i < methodSymbol.Parameters.Length; ++i)
            {
                var parameter = methodSymbol.Parameters[i];

                if (parameter.RefKind == RefKind.Out || parameter.RefKind == RefKind.Ref)
                {
                    var nameOfMethodToCall = parameter.RefKind == RefKind.Out ? "GetOutParameterValue" : "GetRefParameterValue";

                    yield return syntaxGenerator
                        .AssignmentStatement(
                            syntaxGenerator.IdentifierName(parameter.Name),
                            syntaxGenerator
                            .InvocationExpression(
                                syntaxGenerator.MemberAccessExpression(
                                    syntaxGenerator.ThisExpression(),
                                    syntaxGenerator.GenericName(
                                        nameOfMethodToCall,
                                        typeArguments: syntaxGenerator.TypeExpression(parameter.Type))),
                                        arguments: new[]
                                        {
                                            syntaxGenerator.ValueReturningLambdaExpression(
                                                lambdaParameterName,
                                                syntaxGenerator.InvocationExpression(
                                                    lambdaInvocation,
                                                    arguments: arguments)),
                                                syntaxGenerator.LiteralExpression(i)
                                        }));
                }
            }

            // GENERATED CODE:
            //
            //     [return] this.Apply(x => x.SomeMethod(param1, param2));
            var applyInvocation = syntaxGenerator
                .InvocationExpression(
                    syntaxGenerator.MemberAccessExpression(
                        syntaxGenerator.ThisExpression(),
                        "Apply"),
//.........这里部分代码省略.........
开发者ID:modulexcite,项目名称:PCLMock,代码行数:101,代码来源:Generator.cs

示例15: GetPropertySetAccessorsSyntax

        private static IEnumerable<SyntaxNode> GetPropertySetAccessorsSyntax(
            SyntaxGenerator syntaxGenerator,
            SemanticModel semanticModel,
            IPropertySymbol propertySymbol)
        {
            if (propertySymbol.SetMethod == null)
            {
                yield break;
            }

            var lambdaParameterName = GetUniqueName(propertySymbol);

            if (!propertySymbol.IsIndexer)
            {
                // GENERATED CODE:
                //
                //     this.ApplyPropertySet(x => x.PropertyName, value);
                yield return syntaxGenerator
                    .InvocationExpression(
                        syntaxGenerator.MemberAccessExpression(
                            syntaxGenerator.ThisExpression(),
                            "ApplyPropertySet"),
                        syntaxGenerator.ValueReturningLambdaExpression(
                            lambdaParameterName,
                            syntaxGenerator.MemberAccessExpression(
                                syntaxGenerator.IdentifierName(lambdaParameterName),
                                syntaxGenerator.IdentifierName(propertySymbol.Name))),
                        syntaxGenerator.IdentifierName("value"));
            }
            else
            {
                // GENERATED CODE:
                //
                //     this.ApplyPropertySet(x => x[first, second], value);
                var arguments = propertySymbol
                    .Parameters
                    .Select(x => syntaxGenerator.Argument(syntaxGenerator.IdentifierName(x.Name)))
                    .ToList();

                yield return syntaxGenerator
                    .InvocationExpression(
                        syntaxGenerator.MemberAccessExpression(
                            syntaxGenerator.ThisExpression(),
                            "ApplyPropertySet"),
                        syntaxGenerator.ValueReturningLambdaExpression(
                            lambdaParameterName,
                            syntaxGenerator.ElementAccessExpression(
                                syntaxGenerator.IdentifierName(lambdaParameterName),
                                arguments)),
                        syntaxGenerator.IdentifierName("value"));
            }
        }
开发者ID:modulexcite,项目名称:PCLMock,代码行数:52,代码来源:Generator.cs


注:本文中的SyntaxGenerator.MemberAccessExpression方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。