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


C# Syntax.ExpressionStatementSyntax类代码示例

本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionStatementSyntax的典型用法代码示例。如果您正苦于以下问题:C# ExpressionStatementSyntax类的具体用法?C# ExpressionStatementSyntax怎么用?C# ExpressionStatementSyntax使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ExpressionStatementSyntax类属于Microsoft.CodeAnalysis.CSharp.Syntax命名空间,在下文中一共展示了ExpressionStatementSyntax类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: VisitExpressionStatement

 public override void VisitExpressionStatement(ExpressionStatementSyntax node)
 {
   // hack: Console.WriteLine
   var s = node.Expression.GetText().ToString().Trim();
   if (s.StartsWith("Console.WriteLine"))
   {
     var ise = node.Expression as InvocationExpressionSyntax;
     var args = ise.ArgumentList;
     cb.AppendWithIndent("cout << ")
       .Append(args.GetText().ToString().Trim('(', ')').Replace(" + ", " << ").Replace("+", " << "))
       .AppendLine(" << endl;");
   }
   else if (s.StartsWith("Environment.Exit"))
   {
     var ise = node.Expression as InvocationExpressionSyntax;
     var args = ise.ArgumentList;
     cb.AppendWithIndent("exit(")
       .Append(args.GetText().ToString().Trim('(', ')'))
       .AppendLine(");");
   }
   else
   {
     base.VisitExpressionStatement(node);
   }
 }
开发者ID:codedecay,项目名称:Blackmire,代码行数:25,代码来源:CppImplWalker.cs

示例2: RewriteStatement

        /// <summary>
        /// Rewrites the statement with a raise statement.
        /// </summary>
        /// <param name="node">ExpressionStatementSyntax</param>
        /// <returns>SyntaxNode</returns>
        private SyntaxNode RewriteStatement(ExpressionStatementSyntax node)
        {
            var invocation = node.Expression as InvocationExpressionSyntax;

            var arguments = new List<ArgumentSyntax>();
            arguments.Add(invocation.ArgumentList.Arguments[0]);

            string payload = "";
            for (int i = 1; i < invocation.ArgumentList.Arguments.Count; i++)
            {
                if (i == invocation.ArgumentList.Arguments.Count - 1)
                {
                    payload += invocation.ArgumentList.Arguments[i].ToString();
                }
                else
                {
                    payload += invocation.ArgumentList.Arguments[i].ToString() + ", ";
                }
            }

            arguments[0] = SyntaxFactory.Argument(SyntaxFactory.ParseExpression(
                "new " + arguments[0].ToString() + "(" + payload + ")"));
            invocation = invocation.WithArgumentList(SyntaxFactory.ArgumentList(
                SyntaxFactory.SeparatedList(arguments)));

            var text = "{ " +
                node.WithExpression(invocation.WithExpression(SyntaxFactory.IdentifierName("this.Raise"))).ToString() +
                "return; }";
            var rewritten = SyntaxFactory.ParseStatement(text);
            rewritten = rewritten.WithTriviaFrom(node);

            return rewritten;
        }
开发者ID:yonglehou,项目名称:PSharp,代码行数:38,代码来源:RaiseRewriter.cs

示例3: VisitExpressionStatement

        public override SyntaxNode VisitExpressionStatement(ExpressionStatementSyntax node)
        {
            var extension = null as SyntacticalExtension<SyntaxNode>;
            var expr = node.Expression;
            InvocationExpressionSyntax call = null;

            if (expr is InvocationExpressionSyntax)
                call = expr as InvocationExpressionSyntax;
            else if (expr is AssignmentExpressionSyntax)
            {
                var assignment = expr as AssignmentExpressionSyntax;
                call = assignment.Right as InvocationExpressionSyntax;
            }

            if (call != null)
                extension = codeExtension(call);

            if (extension != null)
            {

                if (extension.Kind != ExtensionKind.Code)
                {
                    //td: error, incorrect extension (i.e. a code extension being used inside a type)
                    return node;
                }

                _lookahead = CheckCodeExtension(node, extension);
                return null;
            }

            return node;
        }
开发者ID:mpmedia,项目名称:Excess,代码行数:32,代码来源:ExtensionRewriter.cs

示例4: VisitExpressionStatement

		/// <summary>
		///     Normalizes the <paramref name="statement" /> if it is an invocation of a <c>SetInitialValues</c> method.
		/// </summary>
		public override SyntaxNode VisitExpressionStatement(ExpressionStatementSyntax statement)
		{
			var invocationExpression = statement.Expression as InvocationExpressionSyntax;
			if (invocationExpression == null)
				return base.VisitExpressionStatement(statement);

			var methodSymbol = invocationExpression.GetReferencedSymbol(SemanticModel);
			if (methodSymbol.Name != "SetInitialValues" || !methodSymbol.IsStatic)
				return base.VisitExpressionStatement(statement);

			var isComponentMethod = methodSymbol.ContainingType.Equals(Compilation.GetComponentClassSymbol());
			var isFaultMethod = methodSymbol.ContainingType.Equals(Compilation.GetFaultClassSymbol());
			var isOccurrenceMethod = methodSymbol.ContainingType.Equals(Compilation.GetOccurrencePatternClassSymbol());

			if (!isComponentMethod && !isFaultMethod && !isOccurrenceMethod)
				return base.VisitExpressionStatement(statement);

			// MetadataBuilders.GetBuilder(this)
			var metadataBuilderSymbol = Syntax.TypeExpression(Compilation.GetTypeSymbol(typeof(MetadataBuilders)));
			var getBuilderMethod = Syntax.MemberAccessExpression(metadataBuilderSymbol, "GetBuilder");
			var builder = Syntax.InvocationExpression(getBuilderMethod, Syntax.ThisExpression());

			// ReflectionHelpers.GetField(typeof(...), typeof(...), "...")
			var fieldSymbol = invocationExpression.ArgumentList.Arguments[0].Expression.GetReferencedSymbol<IFieldSymbol>(SemanticModel);
			var fieldInfo = fieldSymbol.GetFieldInfoExpression(Syntax);

			// .WithInitialValues()
			var withInitialValues = Syntax.MemberAccessExpression(builder, Syntax.GenericName("WithInitialValues", fieldSymbol.Type));
			var arguments = new List<ArgumentSyntax>(invocationExpression.ArgumentList.Arguments.Skip(1));
			arguments.Insert(0, (ArgumentSyntax)Syntax.Argument(fieldInfo));
			return Syntax.ExpressionStatement(Syntax.InvocationExpression(withInitialValues, arguments)).EnsureLineCount(statement);
		}
开发者ID:cubeme,项目名称:safety-sharp,代码行数:35,代码来源:InitialValuesNormalizer.cs

示例5: VisitExpressionStatement

		/// <summary>
		///     Normalizes the <paramref name="statement" /> if it is an invocation of a state machine method.
		/// </summary>
		public override SyntaxNode VisitExpressionStatement(ExpressionStatementSyntax statement)
		{
			var invocationExpression = statement.Expression as InvocationExpressionSyntax;
			if (invocationExpression == null)
				return base.VisitExpressionStatement(statement);

			var methodSymbol = invocationExpression.GetReferencedSymbol(SemanticModel);
			if (!methodSymbol.IsStatic)
				return base.VisitExpressionStatement(statement);

			if (methodSymbol.Name != "InitialState" && methodSymbol.Name != "InitialStates" && methodSymbol.Name != "Transition")
				return base.VisitExpressionStatement(statement);

			var isComponentMethod = methodSymbol.ContainingType.Equals(Compilation.GetComponentClassSymbol());
			if (!isComponentMethod)
				return base.VisitExpressionStatement(statement);

			// MetadataBuilders.GetBuilder(this)
			var metadataBuilderSymbol = Syntax.TypeExpression(Compilation.GetTypeSymbol(typeof(MetadataBuilders)));
			var getBuilderMethod = Syntax.MemberAccessExpression(metadataBuilderSymbol, "GetBuilder");
			var builder = Syntax.InvocationExpression(getBuilderMethod, Syntax.ThisExpression());

			if (methodSymbol.Name == "Transition")
				return SyntaxFactory.Block(NormalizeTransitions(builder, invocationExpression)).NormalizeWhitespace().EnsureLineCount(statement);

			// .WithInitialStates(states)
			var withInitialStates = Syntax.MemberAccessExpression(builder, "WithInitialStates");
			var arguments = invocationExpression.ArgumentList.Arguments;
			return Syntax.ExpressionStatement(Syntax.InvocationExpression(withInitialStates, arguments)).EnsureLineCount(statement);
		}
开发者ID:cubeme,项目名称:safety-sharp,代码行数:33,代码来源:StateMachineNormalizer.cs

示例6: VisitExpressionStatement

		/// <summary>
		///   Normalizes the <paramref name="statement" />.
		/// </summary>
		public override SyntaxNode VisitExpressionStatement(ExpressionStatementSyntax statement)
		{
			var transformed = TransformExpression(statement.Expression);
			if (transformed == null)
				return statement;

			return transformed.EnsureLineCount(statement);
		}
开发者ID:isse-augsburg,项目名称:ssharp,代码行数:11,代码来源:TransitionNormalizer.cs

示例7: RewriteStatement

        /// <summary>
        /// Rewrites the raise statement.
        /// </summary>
        /// <param name="node">ExpressionStatementSyntax</param>
        /// <returns>SyntaxNode</returns>
        private SyntaxNode RewriteStatement(ExpressionStatementSyntax node)
        {
            var text = "{ " + node.ToString() + "return; }";
            var rewritten = SyntaxFactory.ParseStatement(text);
            rewritten = rewritten.WithTriviaFrom(node);

            return rewritten;
        }
开发者ID:yonglehou,项目名称:PSharp,代码行数:13,代码来源:RaiseRewriter.cs

示例8: CheckForCondition

 private static void CheckForCondition(SyntaxNodeAnalysisContext context, InvocationExpressionSyntax invocationNode,
   ExpressionStatementSyntax expressionStatementParent, DiagnosticDescriptor descriptor)
 {
   // Make sure the invocation's containing type is not the same as the class that contains it
   if ((invocationNode.DescendantNodesAndTokens().Any(_ => _.IsKind(SyntaxKind.DotToken)) &&
     !invocationNode.DescendantNodesAndTokens().Any(_ => _.IsKind(SyntaxKind.ThisExpression) || _.IsKind(SyntaxKind.BaseExpression))) &&
     (!expressionStatementParent?.DescendantNodesAndTokens()?.Any(_ => _.IsKind(SyntaxKind.EqualsToken)) ?? false) &&
     !(invocationNode.DescendantNodes()?.Any(_ => new ContainsInvocationExpressionWalker(_).HasIssue) ?? false) &&
     !FindSaveAssignmentIssueAnalyzer.IsReturnValue(invocationNode))
   {
     context.ReportDiagnostic(Diagnostic.Create(descriptor, invocationNode.GetLocation()));
   }
 }
开发者ID:MarimerLLC,项目名称:csla,代码行数:13,代码来源:FindSaveAssignmentIssueAnalyzer.cs

示例9: UseExistenceOperatorAsyncWithAssignmentAsync

 private static async Task<Document> UseExistenceOperatorAsyncWithAssignmentAsync(Document document, IfStatementSyntax ifStatement, CancellationToken cancellationToken, ExpressionStatementSyntax expressionIf)
 {
     var memberAccessAssignment = (AssignmentExpressionSyntax)expressionIf.Expression;
     var newMemberAccess = ((MemberAccessExpressionSyntax)memberAccessAssignment.Right).ToConditionalAccessExpression();
     var newExpressionStatement = SyntaxFactory.ExpressionStatement(SyntaxFactory.AssignmentExpression(SyntaxKind.SimpleAssignmentExpression, memberAccessAssignment.Left, newMemberAccess))
         .WithLeadingTrivia(ifStatement.GetLeadingTrivia())
         .WithTrailingTrivia(ifStatement.GetTrailingTrivia())
         .WithAdditionalAnnotations(Formatter.Annotation);
     var root = await document.GetSyntaxRootAsync(cancellationToken);
     var newRoot = root.ReplaceNode(ifStatement, newExpressionStatement);
     var newDocument = document.WithSyntaxRoot(newRoot);
     return newDocument;
 }
开发者ID:JeanLLopes,项目名称:code-cracker,代码行数:13,代码来源:ExistenceOperatorCodeFixProvider.cs

示例10: CreateRootAddingDisposeToEndOfMethod

 private static SyntaxNode CreateRootAddingDisposeToEndOfMethod(SyntaxNode root, ExpressionStatementSyntax statement, ILocalSymbol identitySymbol)
 {
     var method = statement.FirstAncestorOrSelf<MethodDeclarationSyntax>();
     var newDispose = ImplementsDisposableExplicitly(identitySymbol.Type)
         ? SyntaxFactory.ExpressionStatement(SyntaxFactory.InvocationExpression(
             SyntaxFactory.MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression,
             SyntaxFactory.ParenthesizedExpression(SyntaxFactory.CastExpression(SyntaxFactory.ParseName("System.IDisposable").WithAdditionalAnnotations(Simplifier.Annotation), SyntaxFactory.IdentifierName(identitySymbol.Name))),
             SyntaxFactory.IdentifierName("Dispose"))))
         : SyntaxFactory.ParseStatement($"{identitySymbol.Name}.Dispose();");
     newDispose = newDispose.WithAdditionalAnnotations(Formatter.Annotation);
     var last = method.Body.Statements.Last();
     var newRoot = root.InsertNodesAfter(method.Body.Statements.Last(), new[] { newDispose });
     return newRoot;
 }
开发者ID:JeanLLopes,项目名称:code-cracker,代码行数:14,代码来源:DisposableVariableNotDisposedCodeFixProvider.cs

示例11: VisitExpressionStatement

        public override void VisitExpressionStatement(ExpressionStatementSyntax node)
        {
            if (node.DescendantNodes().OfType<IdentifierNameSyntax>().Any(a => "WaitAll".Equals(a.ToString()))
                && node.Parent.ChildNodes().Any(a => a.ToString().Contains("StartNew"))
                && !node.Parent.ChildNodes().Any(a => a is ForStatementSyntax)
                && !node.Parent.ChildNodes().Any(a => a is ForEachStatementSyntax))
            {
                if (Id.ToLower().Contains("test"))
                    Helper.WriteInstance(InvokeTestFile, Id, node.Parent.ToString());
                else
                    Helper.WriteInstance(InvokeFile, Id, node.Parent.ToString());
            }

            base.VisitExpressionStatement(node);
        }
开发者ID:modulexcite,项目名称:concurrent-code-analyses,代码行数:15,代码来源:ThreadTaskAnalysisWalker.cs

示例12: VisitExpressionStatement

        public override SyntaxNode VisitExpressionStatement(ExpressionStatementSyntax node)
        {
            SyntaxNode retVal = null;

            if (node.Expression.Kind() == SyntaxKind.AddAssignmentExpression ||
                node.Expression.Kind() == SyntaxKind.SubtractAssignmentExpression ||
                node.Expression.Kind() == SyntaxKind.MultiplyAssignmentExpression ||
                node.Expression.Kind() == SyntaxKind.DivideAssignmentExpression)
            {
                var add = node.Expression as BinaryExpressionSyntax;
                var printValueStmt = add.Left.GetText();

                retVal = base.VisitExpressionStatement(node);
            }

            return base.VisitExpressionStatement(node);
        }
开发者ID:afrog33k,项目名称:SharpPlayground,代码行数:17,代码来源:CodeRewriter.cs

示例13: AssignMethodReturnToReceiverAsync

        private async Task<Document> AssignMethodReturnToReceiverAsync(CodeFixContext context, Document document, ExpressionStatementSyntax statement, string receiverName, CancellationToken c)
        {
            var rValueExpr = statement.ToString();
            var root = await context.Document.GetSyntaxRootAsync(context.CancellationToken);
            var memberAccess = root.FindNode(context.Span)?.FirstAncestorOrSelf<MemberAccessExpressionSyntax>();

            var declaration = SyntaxFactory
                .ParseStatement($"{receiverName} = {rValueExpr}");

            var formattedDeclaration = declaration.WithTriviaFrom(statement);
            // Replace the old statement with the block:
            var newRoot = root.ReplaceNode((SyntaxNode)statement, formattedDeclaration);

            var newDocument = document.WithSyntaxRoot(newRoot);
            return newDocument;

        }
开发者ID:Winsto,项目名称:MVA-Roslyn,代码行数:17,代码来源:PureMethodsFixer.cs

示例14: VisitExpressionStatement

		/// <summary>
		///   Normalizes the <paramref name="statement" />.
		/// </summary>
		public override SyntaxNode VisitExpressionStatement(ExpressionStatementSyntax statement)
		{
			if (!statement.Expression.IsKind(SyntaxKind.InvocationExpression))
				return statement;

			var expression = (InvocationExpressionSyntax)statement.Expression;
			var methodSymbol = expression.GetReferencedSymbol<IMethodSymbol>(SemanticModel);
			if (!methodSymbol.IsBindMethod(SemanticModel))
				return statement;

			var requiredPortReferenceExpression = (InvocationExpressionSyntax)expression.ArgumentList.Arguments[0].Expression;
			var providedPortReferenceExpression = (InvocationExpressionSyntax)expression.ArgumentList.Arguments[1].Expression;

			var requiredPorts = requiredPortReferenceExpression.ResolvePortReferences(SemanticModel);
			var providedPorts = providedPortReferenceExpression.ResolvePortReferences(SemanticModel);

			requiredPorts.RemoveWhere(symbol => !symbol.IsRequiredPort(SemanticModel));
			providedPorts.RemoveWhere(symbol => symbol.IsRequiredPort(SemanticModel));

			if (methodSymbol.Arity == 1)
			{
				var delegateType = (INamedTypeSymbol)methodSymbol.TypeArguments[0];
				MethodSymbolFilter.Filter(requiredPorts, delegateType);
				MethodSymbolFilter.Filter(providedPorts, delegateType);
			}
			else
				MethodSymbolFilter.Filter(requiredPorts, providedPorts);

			// The analyzer guarantees that there is exactly one port in each set now, but just to be sure...
			Assert.That(requiredPorts.Count == 1, "Expected exactly one required port at this point.");
			Assert.That(providedPorts.Count == 1, "Expected exactly one provided port at this point.");

			var requiredPortExpression = requiredPortReferenceExpression.ArgumentList.Arguments[0].Expression;
			var providedPortExpression = providedPortReferenceExpression.ArgumentList.Arguments[0].Expression;

			var requiredPortReference = CreatePortReference(requiredPorts.Single(), requiredPortExpression);
			var providedPortReference = CreatePortReference(providedPorts.Single(), providedPortExpression);

			var binderType = Syntax.TypeExpression(SemanticModel.GetTypeSymbol(typeof(PortBinding)));
			var binderInstance = Syntax.ObjectCreationExpression(binderType, requiredPortReference, providedPortReference);
			var bindMemberAccess = Syntax.MemberAccessExpression(binderInstance, nameof(PortBinding.Bind));
			var invocation = (ExpressionSyntax)Syntax.InvocationExpression(bindMemberAccess);

			return statement.WithExpression(invocation).NormalizeWhitespace().WithTrivia(statement).PrependLineDirective(statement.GetLineNumber());
		}
开发者ID:isse-augsburg,项目名称:ssharp,代码行数:48,代码来源:BindingNormalizer.cs

示例15: RewriteStatement

        /// <summary>
        /// Rewrites the statement with a raise statement.
        /// </summary>
        /// <param name="node">ExpressionStatementSyntax</param>
        /// <returns>SyntaxNode</returns>
        private SyntaxNode RewriteStatement(ExpressionStatementSyntax node)
        {
            var invocation = node.Expression as InvocationExpressionSyntax;
            var arguments = new List<ArgumentSyntax>(invocation.ArgumentList.Arguments);

            arguments[0] = SyntaxFactory.Argument(SyntaxFactory.ParseExpression(
                "new " + arguments[0].ToString() + "()"));
            invocation = invocation.WithArgumentList(SyntaxFactory.ArgumentList(
                SyntaxFactory.SeparatedList(arguments)));
            
            var text = "{ " +
                node.WithExpression(invocation.WithExpression(SyntaxFactory.IdentifierName("this.Raise"))).ToString() +
                "return; }";
            var rewritten = SyntaxFactory.ParseStatement(text);
            rewritten = rewritten.WithTriviaFrom(node);

            return rewritten;
        }
开发者ID:huangpf,项目名称:PSharp,代码行数:23,代码来源:RaiseRewriter.cs


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