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


C# SyntaxGenerator.InvocationExpression方法代码示例

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


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

示例1: 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

示例2: 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

示例3: CreateProxyInvocationStatement

      private SyntaxNode CreateProxyInvocationStatement(Compilation compilation, SyntaxGenerator g, GenerationNameTable nameTable, IMethodSymbol sourceMethod)
      {
         bool isAsync = ReturnsTask(compilation, sourceMethod);
         bool isVoid = IsVoid(compilation, sourceMethod);

         // proxy.Method(arg1, arg2, ...);
         SyntaxNode invocation = g.InvocationExpression(
                                    g.MemberAccessExpression(
                                       g.IdentifierName(nameTable[MemberNames.ProxyVariable]),
                                       sourceMethod.Name
                                    ),
                                    sourceMethod.Parameters.Select(p => g.IdentifierName(p.Name))
                                 );

         if (isAsync)
         {
            // await proxy.Method(arg1, arg2, ...).ConfigureAwait(false);
            invocation =
               g.AwaitExpression(
                  g.InvocationExpression(
                     g.MemberAccessExpression(
                        invocation,
                        "ConfigureAwait"
                     ),
                     g.FalseLiteralExpression()
                  )
               );
         }

         if (isVoid)
         {
            invocation = g.ExpressionStatement(invocation);
         }
         else
         {
            invocation = g.ReturnStatement(invocation);
         }

         return invocation;

      }
开发者ID:modulexcite,项目名称:WcfClientProxyGenerator,代码行数:41,代码来源:ClientProxyGenerator.ClientClass.cs

示例4: CreateDiagnosticReport

            internal static SyntaxNode CreateDiagnosticReport(SyntaxGenerator generator, string argumentName, string contextName)
            {
                var argumentExpression = generator.IdentifierName(argumentName);
                var argument = generator.Argument(argumentExpression);

                var identifier = generator.IdentifierName(contextName);
                var memberExpression = generator.MemberAccessExpression(identifier, "ReportDiagnostic");
                var expression = generator.InvocationExpression(memberExpression, argument);

                SyntaxNode expressionStatement = generator.ExpressionStatement(expression);
                return expressionStatement;
            }
开发者ID:tmeschter,项目名称:roslyn-analyzers-1,代码行数:12,代码来源:CodeFixProvider.cs

示例5: CreateSpan

            //creates the diagnostic span statement
            internal static SyntaxNode CreateSpan(SyntaxGenerator generator, string startIdentifier, string endIdentifier)
            {
                string name = "diagnosticSpan";
                SyntaxNode memberIdentifier = generator.IdentifierName("TextSpan");
                SyntaxNode memberName = generator.IdentifierName("FromBounds");
                SyntaxNode expression = generator.MemberAccessExpression(memberIdentifier, memberName);

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

                var startSpanIdentifier = generator.IdentifierName(startIdentifier);
                var endSpanIdentifier = generator.IdentifierName(endIdentifier);

                arguments = arguments.Add(startSpanIdentifier);
                arguments = arguments.Add(endSpanIdentifier);

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

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

示例6: WhitespaceCheckHelper

            internal static SyntaxNode WhitespaceCheckHelper(SyntaxGenerator generator, IfStatementSyntax ifStatement, SyntaxList<SyntaxNode> ifBlockStatements)
            {
                var ifOneBlock = ifStatement.Parent as BlockSyntax;
                var ifTwoBlock = 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 trailingTriviaToString = generator.InvocationExpression(generator.MemberAccessExpression(trailingTrivia, "ToString"), arguments);
                var rightSide = generator.LiteralExpression(" ");
                var equalsExpression = generator.ValueEqualsExpression(trailingTriviaToString, rightSide);

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

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

示例7: TriviaVarMissingHelper

            internal static SyntaxNode TriviaVarMissingHelper(SyntaxGenerator generator, IfStatementSyntax declaration)
            {
                var methodDecl = declaration.Parent.AncestorsAndSelf().OfType<MethodDeclarationSyntax>().First();
                var methodBlock = methodDecl.Body as BlockSyntax;
                var secondStatement = methodBlock.Statements[1] as LocalDeclarationStatementSyntax;

                var variableName = generator.IdentifierName(secondStatement.Declaration.Variables[0].Identifier.ValueText);

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

                var localDeclaration = generator.LocalDeclarationStatement("trailingTrivia", variableExpression);

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

示例8: WhitespaceCheckHelper

            // creates the whitespace check
            protected internal static SyntaxNode WhitespaceCheckHelper(SyntaxGenerator generator, IfStatementSyntax ifStatement, SyntaxList<SyntaxNode> ifBlockStatements)
            {
                var ifBlock = ifStatement.Parent as BlockSyntax;
                string variableName = GetTrailingTriviaName(ifBlock);
                SyntaxNode identifierName = generator.IdentifierName(variableName);

                var arguments = new SyntaxList<SyntaxNode>();
                SyntaxNode trailingTriviaToString = generator.InvocationExpression(generator.MemberAccessExpression(identifierName, "ToString"), arguments);
                SyntaxNode rightSide = generator.LiteralExpression(" ");
                SyntaxNode equalsExpression = generator.ValueEqualsExpression(trailingTriviaToString, rightSide);

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

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

示例9: CreateCloseProxyMethod

 private SyntaxNode CreateCloseProxyMethod(Compilation compilation, SyntaxGenerator g, GenerationNameTable nameTable, bool asAsync)
 {
    return
       g.MethodDeclaration(
          asAsync ? nameTable[MemberNames.CloseProxyAsyncMethod] : nameTable[MemberNames.CloseProxyMethod],
          returnType: asAsync ? g.TypeExpression(compilation.RequireType<Task>()) : null,
          parameters: new SyntaxNode[] { g.ParameterDeclaration("alwaysAbort", g.TypeExpression(SpecialType.System_Boolean)) },
          modifiers: asAsync ? DeclarationModifiers.Async : DeclarationModifiers.None,
          accessibility: Accessibility.Private,
          statements: new SyntaxNode[]
          {
             g.IfStatement(
                g.ReferenceNotEqualsExpression(
                   g.IdentifierName(nameTable[MemberNames.CachedProxyField]),
                   g.NullLiteralExpression()
                ),
                new SyntaxNode[]
                {
                   g.LocalDeclarationStatement(
                      "proxy",
                      g.TryCastExpression(
                         g.MemberAccessExpression(
                            g.ThisExpression(),
                            nameTable[MemberNames.CachedProxyField]
                         ),
                         compilation.RequireTypeByMetadataName("System.ServiceModel.ICommunicationObject")
                      )
                   ),
                   g.TryFinallyStatement(
                      new SyntaxNode[]
                      {
                         AwaitExpressionIfAsync(g, asAsync,
                            g.InvocationExpression(
                               g.IdentifierName(asAsync ? nameTable[MemberNames.CloseProxyAsyncMethod] : nameTable[MemberNames.CloseProxyMethod]),
                               g.IdentifierName("proxy"),
                               g.IdentifierName("alwaysAbort")
                            )
                         )
                      },
                      new SyntaxNode[]
                      {
                         g.AssignmentStatement(
                            g.MemberAccessExpression(
                               g.ThisExpression(),
                               nameTable[MemberNames.CachedProxyField]
                            ),
                            g.NullLiteralExpression()
                         )
                      }
                   )
                }
             )
          }
       );
 }
开发者ID:modulexcite,项目名称:WcfClientProxyGenerator,代码行数:55,代码来源:ClientProxyGenerator.ClientClass.cs

示例10: CreateStaticCloseProxyMethod

      private SyntaxNode CreateStaticCloseProxyMethod(Compilation compilation, SyntaxGenerator g, GenerationNameTable nameTable, bool asAsync)
      {
         //private static void CloseProxy(System.ServiceModel.ICommunicationObject proxy, bool alwaysAbort)
         //{
         //   try
         //   {
         //      if (proxy != null && proxy.State != System.ServiceModel.CommunicationState.Closed)
         //      {
         //         if (!alwaysAbort && proxy.State != System.ServiceModel.CommunicationState.Faulted)
         //         {
         //            proxy.Close();
         //         }
         //         else
         //         {
         //            proxy.Abort();
         //         }
         //      }
         //   }
         //   catch (System.ServiceModel.CommunicationException)
         //   {
         //      proxy.Abort();
         //   }
         //   catch (System.TimeoutException)
         //   {
         //      proxy.Abort();
         //   }
         //   catch
         //   {
         //      proxy.Abort();
         //      throw;
         //   }
         //}                  
         
         return g.MethodDeclaration(
            asAsync ? nameTable[MemberNames.CloseProxyAsyncMethod] : nameTable[MemberNames.CloseProxyMethod],
            accessibility: Accessibility.Private,
            returnType: asAsync ? g.TypeExpression(compilation.RequireType<Task>()) : null,
            modifiers: (asAsync ? DeclarationModifiers.Async : DeclarationModifiers.None) | DeclarationModifiers.Static,
            parameters: new SyntaxNode[]
            {
               g.ParameterDeclaration("proxy", g.TypeExpression(compilation.RequireTypeByMetadataName("System.ServiceModel.ICommunicationObject"))),
               g.ParameterDeclaration("alwaysAbort", g.TypeExpression(SpecialType.System_Boolean))

            },
            statements: new SyntaxNode[]
            {
               g.TryCatchStatement(
                  new SyntaxNode[]
                  {
                     // if (proxy != null && proxy.State != System.ServiceModel.CommunicationState.Closed)
                     g.IfStatement(
                        g.LogicalAndExpression(
                           g.ReferenceNotEqualsExpression(
                              g.IdentifierName("proxy"),
                              g.NullLiteralExpression()
                           ),
                           g.ValueNotEqualsExpression(
                              g.MemberAccessExpression(
                                 g.IdentifierName("proxy"),
                                 "State"
                              ),
                              g.DottedName("System.ServiceModel.CommunicationState.Closed")
                           )
                        ),
                        new SyntaxNode[]
                        {
                           // if (!alwaysAbort && proxy.State != System.ServiceModel.CommunicationState.Faulted)
                           g.IfStatement(
                              g.LogicalAndExpression(
                                 g.LogicalNotExpression(
                                    g.IdentifierName("alwaysAbort")
                                 ),
                                 g.ValueNotEqualsExpression(
                                    g.MemberAccessExpression(
                                       g.IdentifierName("proxy"),
                                       "State"
                                    ),
                                    g.DottedName("System.ServiceModel.CommunicationState.Faulted")
                                 )
                              ),
                              new SyntaxNode[]
                              {
                                 g.ExpressionStatement(
                                 asAsync ? 
                                 // await System.Threading.Tasks.Task.Factory.FromAsync(proxy.BeginClose, proxy.EndClose, null).ConfigureAwait(false);
                                 AwaitExpression(g,
                                    g.InvocationExpression(
                                       g.DottedName("System.Threading.Tasks.Task.Factory.FromAsync"),
                                       g.DottedName("proxy.BeginClose"),
                                       g.DottedName("proxy.EndClose"),
                                       g.NullLiteralExpression()
                                    )
                                 )
                                 :
                                 // proxy.Close();
                                 g.InvocationExpression(
                                       g.MemberAccessExpression(
                                          g.IdentifierName("proxy"),
                                          "Close"
                                       )
//.........这里部分代码省略.........
开发者ID:modulexcite,项目名称:WcfClientProxyGenerator,代码行数:101,代码来源:ClientProxyGenerator.ClientClass.cs

示例11: GenerateClientClass


//.........这里部分代码省略.........
               var lambda = gen.ValueReturningLambdaExpression(                  
                  gen.ObjectCreationExpression(gen.IdentifierName(gen.GetName(proxyClass)), ctor.Parameters.Select(p => gen.IdentifierName(p.Name)))
               );

               targetCtor = gen.WithThisConstructorInitializer(targetCtor, new[] { lambda });

               targetCtor = gen.AddWarningCommentIf(!suppressWarningComments, targetCtor);
               targetCtor = gen.WithAccessibility(targetCtor, ToAccessibility(constructorAccessibility));
               
               if (ctorEntry.IsLast)
               {
                  targetCtor = targetCtor.AddTrailingTrivia(gen.CreateEndRegionTrivia()).AddNewLineTrivia();
               }

               targetClass = gen.AddMembers(targetClass, targetCtor.AddNewLineTrivia());
            }


         }

         #endregion

         #region Operation Contract Methods

         // ==> catch
         // ==> {
         // ==>    this.CloseProxy(false);
         // ==>    throw;
         // ==> }
         var catchAndCloseProxyStatement = gen.CatchClause(new SyntaxNode[]
            {
               // ==> this.CloseProxy(false);
               gen.ExpressionStatement(
                  gen.InvocationExpression(
                     gen.MemberAccessExpression(
                        gen.ThisExpression(),
                        nameTable[MemberNames.CloseProxyMethod]
                     ),
                     gen.FalseLiteralExpression()
                  )
               ),

               // throw;
               gen.ThrowStatement()
            });


         foreach (var sourceMethodEntry in methods.AsSmartEnumerable())
         {
            var sourceMethod = sourceMethodEntry.Value;

            using (nameTable.PushScope(sourceMethod.Parameters.Select(p => p.Name)))
            {
               bool isAsync = ReturnsTask(semanticModel.Compilation, sourceMethod);
               bool isVoid = sourceMethod.ReturnType.SpecialType == SpecialType.System_Void || sourceMethod.ReturnType.Equals(semanticModel.Compilation.RequireType<Task>());

               SyntaxNode targetMethod = gen.MethodDeclaration(sourceMethod);

               if (sourceMethodEntry.IsFirst)
                  targetMethod = targetMethod.PrependLeadingTrivia(gen.CreateRegionTrivia("Contract Methods")).AddLeadingTrivia(gen.NewLine());

               targetMethod = gen.AddWarningCommentIf(!suppressWarningComments, targetMethod);

               targetMethod = gen.WithModifiers(targetMethod, isAsync ? DeclarationModifiers.Async : DeclarationModifiers.None);

开发者ID:modulexcite,项目名称:WcfClientProxyGenerator,代码行数:65,代码来源:ClientProxyGenerator.ClientClass.cs

示例12: CreateGetProxyMethod

 private SyntaxNode CreateGetProxyMethod(Compilation compilation, SyntaxGenerator g, INamedTypeSymbol proxyInterface, GenerationNameTable nameTable, bool isAsync)
 {
    //private IProxy GetProxy()
    //{
    //   EnsureProxy();
    //   return m_cachedProxy;
    //}
    return g.MethodDeclaration(
       isAsync ? nameTable[MemberNames.GetProxyAsyncMethod] : nameTable[MemberNames.GetProxyMethod],
       returnType: g.TypeExpression(isAsync ? compilation.RequireType(typeof(Task<>)).Construct(proxyInterface) : proxyInterface),
       accessibility: Accessibility.Private,
       modifiers: isAsync ? DeclarationModifiers.Async : DeclarationModifiers.None,
       statements: new SyntaxNode[]
       {
          g.ExpressionStatement(
             AwaitExpressionIfAsync(g, isAsync,
                g.InvocationExpression(
                   g.MemberAccessExpression(
                      g.ThisExpression(),
                      isAsync ? nameTable[MemberNames.EnsureProxyAsyncMethod] : nameTable[MemberNames.EnsureProxyMethod]
                   )
                )
             )
          ),
          g.ReturnStatement(
             g.MemberAccessExpression(
                g.ThisExpression(),
                nameTable[MemberNames.CachedProxyField]
             )
          )
       }
    );
 }
开发者ID:modulexcite,项目名称:WcfClientProxyGenerator,代码行数:33,代码来源:ClientProxyGenerator.ClientClass.cs

示例13: CreateCancellableProxyInvocationStatement

 private SyntaxNode CreateCancellableProxyInvocationStatement(Compilation compilation, SyntaxGenerator g, GenerationNameTable nameTable, IMethodSymbol sourceMethod)
 {
    //using (cancellationToken.Register(s => CloseProxy((System.ServiceModel.ICommunicationObject)s, true), proxy, false))
    string stateVariableName = GetUniqueParameterName("s", sourceMethod);
    return g.UsingStatement(
       g.InvocationExpression(
          g.MemberAccessExpression(
             g.IdentifierName(nameTable[MemberNames.CancellationTokenParameter]),
                "Register"
          ),
          g.ValueReturningLambdaExpression(
             stateVariableName,
             g.InvocationExpression(
                g.IdentifierName(nameTable[MemberNames.CloseProxyMethod]),
                g.CastExpression(
                   compilation.RequireTypeByMetadataName("System.ServiceModel.ICommunicationObject"),
                   g.IdentifierName(stateVariableName)
                ),
                g.TrueLiteralExpression()
             )
          ),
          g.IdentifierName(nameTable[MemberNames.ProxyVariable]),
          g.FalseLiteralExpression()
       ),
       new SyntaxNode[]
       {
          CreateProxyInvocationStatement(compilation, g, nameTable, sourceMethod)
       }
    );
 }
开发者ID:modulexcite,项目名称:WcfClientProxyGenerator,代码行数:30,代码来源:ClientProxyGenerator.ClientClass.cs

示例14: CreateProxyVaraibleDeclaration

 private SyntaxNode CreateProxyVaraibleDeclaration(SyntaxGenerator g, GenerationNameTable nameTable, bool isAsync)
 {
    // var proxy = this.GetProxy();
    if (!isAsync)
    {
       return g.LocalDeclarationStatement(nameTable[MemberNames.ProxyVariable],
                                        g.InvocationExpression(
                                           g.MemberAccessExpression(
                                              g.ThisExpression(),
                                              g.IdentifierName(nameTable[MemberNames.GetProxyMethod])
                                           )
                                        )
                                     );
    }
    else
    {
       // var proxy = await this.GetProxyAsync().ConfigureAwait(false);                                                
       return
          g.LocalDeclarationStatement(nameTable[MemberNames.ProxyVariable],
             g.AwaitExpression(
                g.InvocationExpression(
                   g.MemberAccessExpression(
                      g.InvocationExpression(
                         g.MemberAccessExpression(
                            g.ThisExpression(),
                            g.IdentifierName(nameTable[MemberNames.GetProxyAsyncMethod])
                         )
                      ), "ConfigureAwait"),
                   g.FalseLiteralExpression()
                )
             )
          );
    }
 }
开发者ID:modulexcite,项目名称:WcfClientProxyGenerator,代码行数:34,代码来源:ClientProxyGenerator.ClientClass.cs

示例15: 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


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