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


C# AssignmentExpressionSyntax.Kind方法代码示例

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


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

示例1: ParseIfStatement

        internal static bool ParseIfStatement(IfStatementSyntax node, out ExpressionSyntax condition, out ExpressionSyntax target, out AssignmentExpressionSyntax whenTrue, out AssignmentExpressionSyntax whenFalse)
        {
            condition = null;
            target = null;
            whenTrue = null;
            whenFalse = null;

            if (node == null || node.Else == null || node.Parent is IfStatementSyntax || node.Else.Statement is IfStatementSyntax)
                return false;

            condition = node.Condition;
            //make sure to check for multiple statements
            ExpressionStatementSyntax whenTrueExprStatement, whenFalseExprStatement;
            var embeddedBlock = node.Statement as BlockSyntax;
            if (embeddedBlock != null)
            {
                if (embeddedBlock.Statements.Count > 1)
                    return false;
                var childNodes = embeddedBlock.ChildNodes();
                if (childNodes.Count() > 1)
                    return false;
                whenTrueExprStatement = childNodes.OfType<ExpressionStatementSyntax>().FirstOrDefault();
            }
            else
            {
                whenTrueExprStatement = node.Statement as ExpressionStatementSyntax;
            }

            var elseBlock = node.Else.Statement as BlockSyntax;
            if (elseBlock != null)
            {
                if (elseBlock.Statements.Count > 1)
                    return false;
                var childNodes = elseBlock.ChildNodes();
                if (childNodes.Count() > 1)
                    return false;
                whenFalseExprStatement = childNodes.OfType<ExpressionStatementSyntax>().FirstOrDefault();
            }
            else
            {
                whenFalseExprStatement = node.Else.Statement as ExpressionStatementSyntax;
            }

            if (whenTrueExprStatement == null || whenFalseExprStatement == null)
                return false;

            whenTrue = whenTrueExprStatement.Expression as AssignmentExpressionSyntax;
            whenFalse = whenFalseExprStatement.Expression as AssignmentExpressionSyntax;
            if (whenTrue == null || whenFalse == null || whenTrue.Kind() != whenFalse.Kind() ||
                !SyntaxFactory.AreEquivalent(whenTrue.Left, whenFalse.Left))
                return false;

            return true;
        }
开发者ID:alecor191,项目名称:RefactoringEssentials,代码行数:54,代码来源:ConvertIfStatementToConditionalTernaryExpressionCodeRefactoringProvider.cs

示例2: VisitAssignmentExpression

		/// <summary>
		///     Normalizes the <paramref name="expression" /> if it represents a compound assignment.
		/// </summary>
		public override SyntaxNode VisitAssignmentExpression(AssignmentExpressionSyntax expression)
		{
			expression = (AssignmentExpressionSyntax)base.VisitAssignmentExpression(expression);

			SyntaxKind expressionKind;
			switch (expression.Kind())
			{
				case SyntaxKind.AddAssignmentExpression:
					expressionKind = SyntaxKind.AddExpression;
					break;
				case SyntaxKind.SubtractAssignmentExpression:
					expressionKind = SyntaxKind.SubtractExpression;
					break;
				case SyntaxKind.MultiplyAssignmentExpression:
					expressionKind = SyntaxKind.MultiplyExpression;
					break;
				case SyntaxKind.DivideAssignmentExpression:
					expressionKind = SyntaxKind.DivideExpression;
					break;
				case SyntaxKind.ModuloAssignmentExpression:
					expressionKind = SyntaxKind.ModuloExpression;
					break;
				case SyntaxKind.AndAssignmentExpression:
					expressionKind = SyntaxKind.LogicalAndExpression;
					break;
				case SyntaxKind.ExclusiveOrAssignmentExpression:
					expressionKind = SyntaxKind.ExclusiveOrExpression;
					break;
				case SyntaxKind.OrAssignmentExpression:
					expressionKind = SyntaxKind.LogicalOrExpression;
					break;
				case SyntaxKind.LeftShiftAssignmentExpression:
					expressionKind = SyntaxKind.LeftShiftExpression;
					break;
				case SyntaxKind.RightShiftAssignmentExpression:
					expressionKind = SyntaxKind.RightShiftExpression;
					break;
				default:
					return expression;
			}

			var originalRightHand = (ExpressionSyntax)Visit(expression.Right);
			var parenthesizedExpression = SyntaxFactory.ParenthesizedExpression(originalRightHand).WithLeadingSpace();
			var rightHandExpression = SyntaxFactory.BinaryExpression(expressionKind, expression.Left.WithLeadingSpace(), parenthesizedExpression);
			var simpleAssignment = SyntaxFactory.AssignmentExpression(SyntaxKind.SimpleAssignmentExpression, expression.Left, rightHandExpression);
			return simpleAssignment.WithTrivia(expression);
		}
开发者ID:cubeme,项目名称:safety-sharp,代码行数:50,代码来源:CompoundAssignmentNormalizer.cs

示例3: TryGenerateAssignment

        private bool TryGenerateAssignment(AssignmentExpressionSyntax binaryExpression)
        {
            var kind = BinaryOperatorKind.None;
            switch (binaryExpression.Kind())
            {
                case SyntaxKind.AddAssignmentExpression:
                    kind = BinaryOperatorKind.AddDelegate;
                    break;
            }

            using (AssignmentTag(kind))
            {
                return TryGenerateExpression(binaryExpression.Left)
                    && TryGenerateExpression(binaryExpression.Right);
            }
        }
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:16,代码来源:MethodXmlBuilder.cs

示例4: MightHaveReferenceBetween

 private static bool MightHaveReferenceBetween(SyntaxNode first, AssignmentExpressionSyntax second, List<IdentifierNameSyntax> references)
 {
     return !DifferentStatementsWithSameParent(first, second) ||
            references.Any(reference =>
                reference.SpanStart < second.SpanStart && reference.SpanStart >= first.Span.End) ||
            ReferenceInAssignmentRight(references, second) ||
            ReadWriteAssignment.Contains(second.Kind());
 }
开发者ID:jango2015,项目名称:sonarlint-vs,代码行数:8,代码来源:DeadStores.cs

示例5: CreateForNullCoalescingExpression

 static IfStatementSyntax CreateForNullCoalescingExpression(AssignmentExpressionSyntax expr, BinaryExpressionSyntax bOp)
 {
     return SyntaxFactory.IfStatement(SyntaxFactory.BinaryExpression(SyntaxKind.NotEqualsExpression, bOp.Left, SyntaxFactory.LiteralExpression(SyntaxKind.NullLiteralExpression)),
         SyntaxFactory.ExpressionStatement(SyntaxFactory.AssignmentExpression(expr.Kind(), expr.Left, bOp.Left)),
         SyntaxFactory.ElseClause(SyntaxFactory.ExpressionStatement(SyntaxFactory.AssignmentExpression(expr.Kind(), expr.Left, bOp.Right))));
 }
开发者ID:alecor191,项目名称:RefactoringEssentials,代码行数:6,代码来源:ConvertTernaryExpressionToIfStatementCodeRefactoringProvider.cs

示例6: CreateForConditionalExpression

 static IfStatementSyntax CreateForConditionalExpression(AssignmentExpressionSyntax expr, ConditionalExpressionSyntax conditional)
 {
     return SyntaxFactory.IfStatement(
         conditional.Condition,
         SyntaxFactory.ExpressionStatement(
             SyntaxFactory.AssignmentExpression(expr.Kind(), expr.Left, conditional.WhenTrue)
         ),
         SyntaxFactory.ElseClause(
             SyntaxFactory.ExpressionStatement(
                 SyntaxFactory.AssignmentExpression(expr.Kind(), expr.Left, conditional.WhenFalse)
             )
         )
     );
 }
开发者ID:alecor191,项目名称:RefactoringEssentials,代码行数:14,代码来源:ConvertTernaryExpressionToIfStatementCodeRefactoringProvider.cs

示例7: VisitAssignmentExpression

        public override SyntaxNode VisitAssignmentExpression(AssignmentExpressionSyntax node)
        {
            node = (AssignmentExpressionSyntax)base.VisitAssignmentExpression(node);
            var left = node.Left;
            var right = node.Right;
            var operatorToken = node.OperatorToken;

            if ((transformKind == TransformKind.AddAssignToAssign) && (node.Kind() == SyntaxKind.AddAssignmentExpression))
            {
                var equalsToken = SyntaxFactory.Token(operatorToken.LeadingTrivia, SyntaxKind.EqualsToken, operatorToken.TrailingTrivia);
                var newLeft = left.WithLeadingTrivia(SyntaxFactory.TriviaList());
                var addExpression = SyntaxFactory.BinaryExpression(SyntaxKind.AddExpression, newLeft, SyntaxFactory.Token(operatorToken.LeadingTrivia, SyntaxKind.PlusToken, operatorToken.TrailingTrivia), right);

                return SyntaxFactory.AssignmentExpression(SyntaxKind.SimpleAssignmentExpression, left, equalsToken, addExpression);
            }

            return node;
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:18,代码来源:TransformVisitor.cs


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