• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# IfElseStatement类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: VisitIfElseStatement

		public override object VisitIfElseStatement(IfElseStatement ifElseStatement, object data)
		{
			BinaryOperatorExpression boe = ifElseStatement.Condition as BinaryOperatorExpression;
			// the BinaryOperatorExpression might be inside a ParenthesizedExpression
			if (boe == null && ifElseStatement.Condition is ParenthesizedExpression) {
				boe = (ifElseStatement.Condition as ParenthesizedExpression).Expression as BinaryOperatorExpression;
			}
			if (ifElseStatement.ElseIfSections.Count == 0
			    && ifElseStatement.FalseStatement.Count == 0
			    && ifElseStatement.TrueStatement.Count == 1
			    && boe != null
			    && boe.Op == BinaryOperatorType.InEquality
			    && (IsNullLiteralExpression(boe.Left) || IsNullLiteralExpression(boe.Right))
			   )
			{
				string ident = GetPossibleEventName(boe.Left) ?? GetPossibleEventName(boe.Right);
				ExpressionStatement se = ifElseStatement.TrueStatement[0] as ExpressionStatement;
				if (se == null) {
					BlockStatement block = ifElseStatement.TrueStatement[0] as BlockStatement;
					if (block != null && block.Children.Count == 1) {
						se = block.Children[0] as ExpressionStatement;
					}
				}
				if (ident != null && se != null) {
					InvocationExpression ie = se.Expression as InvocationExpression;
					if (ie != null && GetPossibleEventName(ie.TargetObject) == ident) {
						ReplaceCurrentNode(new RaiseEventStatement(ident, ie.Arguments));
					}
				}
			}
			return base.VisitIfElseStatement(ifElseStatement, data);
		}
开发者ID:mgagne-atman,项目名称:Projects,代码行数:32,代码来源:CSharpConstructsConvertVisitor.cs


示例2: VisitIfElseStatement

            public override void VisitIfElseStatement(IfElseStatement ifElseStatement)
            {
                base.VisitIfElseStatement (ifElseStatement);

                if (HasRundundantElse(ifElseStatement)) {
                    AddIssue (ifElseStatement.ElseToken, ctx.TranslateString ("Remove redundant 'else'"),
                        script =>
                        {
                            int start = script.GetCurrentOffset(ifElseStatement.ElseToken.GetPrevNode ().EndLocation);
                            int end;

                            var blockStatement = ifElseStatement.FalseStatement as BlockStatement;
                            if (blockStatement != null) {
                                if (blockStatement.Statements.Count == 0) {
                                    // remove empty block
                                    end = script.GetCurrentOffset (blockStatement.LBraceToken.StartLocation);
                                    script.Remove (blockStatement);
                                } else {
                                    // remove block braces
                                    end = script.GetCurrentOffset (blockStatement.LBraceToken.EndLocation);
                                    script.Remove (blockStatement.RBraceToken);
                                }
                            } else {
                                end = script.GetCurrentOffset(ifElseStatement.ElseToken.EndLocation);
                            }
                            if (end > start)
                                script.RemoveText (start, end - start);

                            script.FormatText (ifElseStatement.Parent);
                        });
                }
            }
开发者ID:kaagati,项目名称:NRefactory,代码行数:32,代码来源:RedundantElseIssue.cs


示例3: VisitIfElseStatement

            public override object VisitIfElseStatement(IfElseStatement ifElseStatement, object data)
            {
                if (!ifElseStatement.FalseStatement.IsNull)
                    UnlockWith(ifElseStatement);

                return base.VisitIfElseStatement(ifElseStatement, data);
            }
开发者ID:vlad2135,项目名称:strokes,代码行数:7,代码来源:IfElseStatementAchievement.cs


示例4: VisitIfElseStatement

            public override object VisitIfElseStatement(IfElseStatement ifElseStatement, object data)
            {
                if (ifElseStatement.FalseStatement is IfElseStatement)
                    UnlockWith(ifElseStatement.ElseToken);

                return base.VisitIfElseStatement(ifElseStatement, data);
            }
开发者ID:vlad2135,项目名称:strokes,代码行数:7,代码来源:ElseIfStatementAchievement.cs


示例5: VisitIfElseStatement

            public override object VisitIfElseStatement(IfElseStatement ifElseStatement, object data)
            {
                var expression = ifElseStatement.Condition as UnaryOperatorExpression;
                if (expression != null && expression.Operator == UnaryOperatorType.Not)
                    UnlockWith(ifElseStatement);

                return base.VisitIfElseStatement(ifElseStatement, data);
            }
开发者ID:vlad2135,项目名称:strokes,代码行数:8,代码来源:NotOperatorAchievement.cs


示例6: VisitIfElseStatement

            public override object VisitIfElseStatement(IfElseStatement ifElseStatement, object data)
            {
                var condition = ifElseStatement.Condition as BinaryOperatorExpression;
                if (condition != null && condition.Operator != BinaryOperatorType.Equality)
                    UnlockWith(ifElseStatement);

                return base.VisitIfElseStatement(ifElseStatement, data);
            }
开发者ID:clausjoergensen,项目名称:strokes,代码行数:8,代码来源:IfCompoundExpressionAchievement.cs


示例7: VisitIfElseStatement

		public override void VisitIfElseStatement(IfElseStatement ifElseStatement)
		{
            var token = CreateConditionalBlock(ifElseStatement.Condition.GetText());
            _tokenList.Add(token);

            VisitChildren(token.FalseStatements, ifElseStatement.FalseStatement);
            VisitChildren(token.TrueStatements, ifElseStatement.TrueStatement);            
		}        
开发者ID:JoeHosman,项目名称:sharpDox,代码行数:8,代码来源:MethodVisitor.cs


示例8: HasRundundantElse

			bool HasRundundantElse(IfElseStatement ifElseStatement)
			{
				if (ifElseStatement.FalseStatement.IsNull || ifElseStatement.Parent is IfElseStatement)
					return false;
				var blockStatement = ifElseStatement.FalseStatement as BlockStatement;
				if (blockStatement != null && blockStatement.Statements.Count == 0)
					return true;
				var reachability = ctx.CreateReachabilityAnalysis (ifElseStatement.TrueStatement);
				return !reachability.IsEndpointReachable (ifElseStatement.TrueStatement);
			}
开发者ID:RainsSoft,项目名称:playscript-monodevelop,代码行数:10,代码来源:RedundantElseIssue.cs


示例9: InlineCommentAtEndOfCondition

		public void InlineCommentAtEndOfCondition()
		{
			IfElseStatement condition = new IfElseStatement();
			condition.AddChild(new CSharpTokenNode(new TextLocation(1, 1), 2), IfElseStatement.IfKeywordRole);
			condition.AddChild(new CSharpTokenNode(new TextLocation(1, 4), 1), IfElseStatement.Roles.LPar);
			condition.AddChild(new IdentifierExpression("cond", new TextLocation(1, 5)), IfElseStatement.ConditionRole);
			condition.AddChild(new Comment(CommentType.MultiLine, new TextLocation(1, 9), new TextLocation(1, 14)) { Content = "a" }, IfElseStatement.Roles.Comment);
			condition.AddChild(new CSharpTokenNode(new TextLocation(1, 14), 1), IfElseStatement.Roles.RPar);
			condition.AddChild(new ReturnStatement(), IfElseStatement.TrueRole);
			
			AssertOutput("if (cond/*a*/)\n$return;\n", condition);
		}
开发者ID:N3X15,项目名称:ILSpy,代码行数:12,代码来源:CSharpOutputVisitorTests.cs


示例10: GenerateNewScript

		void GenerateNewScript(Script script, IfElseStatement ifStatement)
		{
			var mergedIfStatement = new IfElseStatement {
				Condition = CSharpUtil.InvertCondition(ifStatement.Condition),
				TrueStatement = new ContinueStatement()
			};
			mergedIfStatement.Condition.AcceptVisitor(_insertParenthesesVisitor);
			
			script.Replace(ifStatement, mergedIfStatement);
			
			SimplifyIfFlowAction.InsertBody(script, ifStatement);
		}
开发者ID:0xb1dd1e,项目名称:NRefactory,代码行数:12,代码来源:SimplifyIfInLoopsFlowAction.cs


示例11: CreateAndSplit

		static CodeAction CreateAndSplit(RefactoringContext context, IfElseStatement ifStatement, BinaryOperatorExpression bOp)
		{
			return new CodeAction(
				context.TranslateString("Split if"),
				script => {
					var nestedIf = (IfElseStatement)ifStatement.Clone();
					nestedIf.Condition = GetRightSide(bOp); 
					script.Replace(ifStatement.Condition, GetLeftSide(bOp));
					script.Replace(ifStatement.TrueStatement, new BlockStatement { nestedIf });
				},
				bOp.OperatorToken
			);
		}
开发者ID:0xb1dd1e,项目名称:NRefactory,代码行数:13,代码来源:SplitIfAction.cs


示例12: InsertBody

        internal static void InsertBody(Script script, IfElseStatement ifStatement)
        {
            var ifBody = ifStatement.TrueStatement.Clone();

            if (ifBody is BlockStatement) {
                AstNode last = ifStatement;
                foreach (var stmt in ((BlockStatement)ifBody).Children) {
                    if (stmt.Role == Roles.LBrace || stmt.Role == Roles.RBrace || stmt.Role == Roles.NewLine)
                        continue;
                    script.InsertAfter(last, stmt);
                    last = stmt;
                }
            } else {
                script.InsertAfter(ifStatement, ifBody);
            }
            script.FormatText(ifStatement.Parent);
        }
开发者ID:segaman,项目名称:NRefactory,代码行数:17,代码来源:SimplifyIfFlowAction.cs


示例13: CreateOrSplit

		static CodeAction CreateOrSplit(RefactoringContext context, IfElseStatement ifStatement, BinaryOperatorExpression bOp)
		{
			return new CodeAction(
				context.TranslateString("Split if"),
				script => {
					var newElse = (IfElseStatement)ifStatement.Clone();
					newElse.Condition = GetRightSide(bOp); 
					
					var newIf = (IfElseStatement)ifStatement.Clone();
					newIf.Condition = GetLeftSide(bOp); 
					newIf.FalseStatement = newElse;

					script.Replace(ifStatement, newIf);
					script.FormatText(newIf);
				},
				bOp.OperatorToken
			);
		}
开发者ID:0xb1dd1e,项目名称:NRefactory,代码行数:18,代码来源:SplitIfAction.cs


示例14: Execute

		public override void Execute(EditorRefactoringContext context)
		{
			CSharpFullParseInformation parseInformation = context.GetParseInformation() as CSharpFullParseInformation;
			if (parseInformation != null) {
				SyntaxTree st = parseInformation.SyntaxTree;
				Identifier identifier = (Identifier) st.GetNodeAt(context.CaretLocation, node => node.Role == Roles.Identifier);
				if (identifier == null)
					return;
				ParameterDeclaration parameterDeclaration = identifier.Parent as ParameterDeclaration;
				if (parameterDeclaration == null)
					return;
				
				AstNode grandparent = identifier.Parent.Parent;
				if ((grandparent is MethodDeclaration) || (grandparent is ConstructorDeclaration)) {
					// Range check condition
					var rangeCheck = new IfElseStatement(
						new BinaryOperatorExpression(
							new BinaryOperatorExpression(new IdentifierExpression(identifier.Name), BinaryOperatorType.LessThan, new IdentifierExpression("lower")),
							BinaryOperatorType.ConditionalOr,
							new BinaryOperatorExpression(new IdentifierExpression(identifier.Name), BinaryOperatorType.GreaterThan, new IdentifierExpression("upper"))
						),
						new ThrowStatement(
							new ObjectCreateExpression(
								new SimpleType("ArgumentOutOfRangeException"),
								new List<Expression>() { new PrimitiveExpression(identifier.Name, '"' + identifier.Name + '"'), new IdentifierExpression(identifier.Name), new BinaryOperatorExpression(new PrimitiveExpression("Value must be between "), BinaryOperatorType.Add, new BinaryOperatorExpression(new IdentifierExpression("lower"), BinaryOperatorType.Add, new BinaryOperatorExpression(new PrimitiveExpression(" and "), BinaryOperatorType.Add, new IdentifierExpression("upper")))) }
							)
						)
					);
					
					// Add range check as first statement in method's/constructor's body
					var refactoringContext = SDRefactoringContext.Create(context.Editor, CancellationToken.None);
					using (Script script = refactoringContext.StartScript()) {
						if (grandparent is MethodDeclaration) {
							var methodDeclaration = (MethodDeclaration) grandparent;
							script.AddTo(methodDeclaration.Body, rangeCheck);
						} else if (grandparent is ConstructorDeclaration) {
							var ctorDeclaration = (ConstructorDeclaration) grandparent;
							script.AddTo(ctorDeclaration.Body, rangeCheck);
						}
					}
				}
			}
		}
开发者ID:2594636985,项目名称:SharpDevelop,代码行数:43,代码来源:ParamRangeCheckContextAction.cs


示例15: VisitIfElseStatement

            public override object VisitIfElseStatement(IfElseStatement ifElseStatement, object data)
            {
                if (ifElseStatement.TrueStatement is BlockStatement)
                {
                    foreach (var statement in (ifElseStatement.TrueStatement as BlockStatement).Statements)
                    {
                        if (statement is IfElseStatement)
                            UnlockWith(ifElseStatement);
                    }
                }

                if (ifElseStatement.FalseStatement is BlockStatement)
                {
                    foreach (var statement in (ifElseStatement.FalseStatement as BlockStatement).Statements)
                    {
                        if (statement is IfElseStatement)
                            UnlockWith(ifElseStatement);
                    }
                }

                return base.VisitIfElseStatement(ifElseStatement, data);
            }
开发者ID:vlad2135,项目名称:strokes,代码行数:22,代码来源:NestedIfStatementAchievement.cs


示例16: VisitIfElseStatement

        public override void VisitIfElseStatement(IfElseStatement node)
        {
            VisitChildren(node);

            var yes = node.TrueStatement;
            var no = node.FalseStatement;
            var constant = BoolConstant(node.Condition);

            // Special-case constant conditions
            if (constant == true) {
                node.ReplaceWith(yes); // Inline "if (true)"
            } else if (constant == false) {
                node.ReplaceWith(no); // Inline "if (false)"
            }

            // Inline single statements
            else {
                ReplaceBlockWithSingleStatement(no);
                if (no.IsNull) {
                    ReplaceBlockWithSingleStatement(yes);
                }

                // Be careful to avoid the dangling-else issue
                else {
                    var block = yes as BlockStatement;
                    if (block != null) {
                        var statements = block.Statements;
                        if (statements.Count == 1) {
                            var first = statements.FirstOrNullObject();
                            var ifElse = first as IfElseStatement;
                            if (ifElse == null || !ifElse.FalseStatement.IsNull) {
                                yes.ReplaceWith(first);
                            }
                        }
                    }
                }
            }
        }
开发者ID:evanw,项目名称:minisharp,代码行数:38,代码来源:Mangle.cs


示例17: VisitIfElseStatement

		public void VisitIfElseStatement(IfElseStatement ifElseStatement)
		{
			StartNode(ifElseStatement);
			WriteKeyword(IfElseStatement.IfKeywordRole);
			Space(policy.SpaceBeforeIfParentheses);
			LPar();
			Space(policy.SpacesWithinIfParentheses);
			ifElseStatement.Condition.AcceptVisitor(this);
			Space(policy.SpacesWithinIfParentheses);
			RPar();
			WriteEmbeddedStatement(ifElseStatement.TrueStatement);
			if (!ifElseStatement.FalseStatement.IsNull) {
				WriteKeyword(IfElseStatement.ElseKeywordRole);
				if (ifElseStatement.FalseStatement is IfElseStatement) {
					// don't put newline between 'else' and 'if'
					ifElseStatement.FalseStatement.AcceptVisitor(this);
				} else {
					WriteEmbeddedStatement(ifElseStatement.FalseStatement);
				}
			}
			EndNode(ifElseStatement);
		}
开发者ID:jeremiahyan,项目名称:ILSpy,代码行数:22,代码来源:CSharpOutputVisitor.cs


示例18: Walk

 // IfElseStatement
 public override bool Walk(IfElseStatement node)
 {
     return false;
 }
开发者ID:Alxandr,项目名称:IronTotem,代码行数:5,代码来源:TotemWalker.cs


示例19: PostWalk

 public override void PostWalk(IfElseStatement node)
 {
 }
开发者ID:Alxandr,项目名称:IronTotem,代码行数:3,代码来源:TotemWalker.cs


示例20: VisitIfElseStatement

		public override void VisitIfElseStatement(IfElseStatement ifElseStatement) {
			var compiledCond = CompileExpression(ifElseStatement.Condition, CompileExpressionFlags.ReturnValueIsImportant);
			_result.AddRange(compiledCond.AdditionalStatements);
			_result.Add(JsStatement.If(compiledCond.Expression, CreateInnerCompiler().Compile(ifElseStatement.TrueStatement), !ifElseStatement.FalseStatement.IsNull ? CreateInnerCompiler().Compile(ifElseStatement.FalseStatement) : null));
		}
开发者ID:chenxustu1,项目名称:SaltarelleCompiler,代码行数:5,代码来源:StatementCompiler.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# IfStatementSyntax类代码示例发布时间:2022-05-24
下一篇:
C# IdmResource类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap