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

C# SwitchStatement类代码示例

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

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



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

示例1: VisitSwitchStatement

            public override object VisitSwitchStatement(SwitchStatement switchStatement, object data)
            {
                foreach (var section in switchStatement.SwitchSections)
                {
                    foreach (var label in section.CaseLabels)
                    {
                        var memberRef = label.Expression as MemberReferenceExpression;
                        var targetObject = memberRef != null ? memberRef.Target as IdentifierExpression : null;
                        if (targetObject != null)
                        {
                            var hasEnums = codebaseDeclarationInfos.Any(a =>
                                     a.Name == targetObject.Identifier &&
                                     a.DeclarationClassType == TypeDeclarationKind.Enum);

                            if (hasEnums)
                            {
                                UnlockWith(switchStatement);
                                break;
                            }
                        }
                    }
                }

                return base.VisitSwitchStatement(switchStatement, data);
            }
开发者ID:vlad2135,项目名称:strokes,代码行数:25,代码来源:EnumSwitchAchievement.cs


示例2: VisitSwitchStatement

        public override void VisitSwitchStatement(SwitchStatement switchStatement)
        {
            var token = CreateBlock(string.Format("switch ({0})", switchStatement.Expression.GetText()), SDNodeRole.Switch);
            _tokenList.Add(token);

            var tmp = _tokenList;
            _tokenList = token.Statements;

            foreach (var section in switchStatement.SwitchSections)
            {
                var caseToken = CreateBlock(string.Join(" ", section.CaseLabels.Select(o => o.GetText())), SDNodeRole.Case);
                _tokenList.Add(caseToken);

                VisitChildren(caseToken.Statements, section);
            }            
        }
开发者ID:JoeHosman,项目名称:sharpDox,代码行数:16,代码来源:MethodVisitor.cs


示例3: Visit

			public override object Visit (Switch switchStatement)
			{
				var result = new SwitchStatement ();
				
				var location = LocationsBag.GetLocations (switchStatement);
				result.AddChild (new CSharpTokenNode (Convert (switchStatement.loc), "switch".Length), SwitchStatement.Roles.Keyword);
				if (location != null)
					result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), SwitchStatement.Roles.LPar);
				result.AddChild ((INode)switchStatement.Expr.Accept (this), SwitchStatement.Roles.Expression);
				if (location != null)
					result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), SwitchStatement.Roles.RPar);
				if (location != null)
					result.AddChild (new CSharpTokenNode (Convert (location[2]), 1), SwitchStatement.Roles.LBrace);
				foreach (var section in switchStatement.Sections) {
					var newSection = new MonoDevelop.CSharp.Dom.SwitchSection ();
					foreach (var caseLabel in section.Labels) {
						var newLabel = new CaseLabel ();
						newLabel.AddChild (new CSharpTokenNode (Convert (caseLabel.Location), "case".Length), SwitchStatement.Roles.Keyword);
						if (caseLabel.Label != null)
							newLabel.AddChild ((INode)caseLabel.Label.Accept (this), SwitchStatement.Roles.Expression);
						
						newSection.AddChild (newLabel, MonoDevelop.CSharp.Dom.SwitchSection.CaseLabelRole);
					}
					newSection.AddChild ((INode)section.Block.Accept (this), MonoDevelop.CSharp.Dom.SwitchSection.Roles.Body);
					result.AddChild (newSection, SwitchStatement.SwitchSectionRole);
				}
				
				if (location != null)
					result.AddChild (new CSharpTokenNode (Convert (location[3]), 1), SwitchStatement.Roles.RBrace);
				return result;
			}
开发者ID:pgoron,项目名称:monodevelop,代码行数:31,代码来源:CSharpParser.cs


示例4: Visit

			public override object Visit(Switch switchStatement)
			{
				var result = new SwitchStatement();
				
				var location = LocationsBag.GetLocations(switchStatement);
				result.AddChild(new CSharpTokenNode(Convert(switchStatement.loc), SwitchStatement.SwitchKeywordRole), SwitchStatement.SwitchKeywordRole);
				if (location != null)
					result.AddChild(new CSharpTokenNode(Convert(location [0]), Roles.LPar), Roles.LPar);
				if (switchStatement.Expr != null)
					result.AddChild((Expression)switchStatement.Expr.Accept(this), Roles.Expression);
				if (location != null && location.Count > 1)
					result.AddChild(new CSharpTokenNode(Convert(location [1]), Roles.RPar), Roles.RPar);
				if (location != null && location.Count > 2)
					result.AddChild(new CSharpTokenNode(Convert(location [2]), Roles.LBrace), Roles.LBrace);
				SwitchSection newSection = null;
				bool lastWasCase = false, added = true;
				if (switchStatement.Block != null) {
					foreach (var child in switchStatement.Block.Statements) {
						var statement = child.Accept(this);
						var caseLabel = statement as CaseLabel;
						if (caseLabel != null) {
							if (!lastWasCase) {
								newSection = new SwitchSection();
								added = false;
							}
							newSection.AddChild(caseLabel, SwitchSection.CaseLabelRole);
							lastWasCase = true;
						} else {
							if (lastWasCase) {
								result.AddChild(newSection, SwitchStatement.SwitchSectionRole);
								lastWasCase = false;
								added = true;
							}
							newSection.AddChild((Statement)statement, Roles.EmbeddedStatement);
						}
					}
				}
				if (!added)
					result.AddChild(newSection, SwitchStatement.SwitchSectionRole);

				if (location != null && location.Count > 3) {
					result.AddChild(new CSharpTokenNode(Convert(location [3]), Roles.RBrace), Roles.RBrace);
				} else {
					// parser error, set end node to max value.
					result.AddChild(new ErrorNode(), Roles.Error);
				}
				
				return result;
			}
开发者ID:0xb1dd1e,项目名称:NRefactory,代码行数:49,代码来源:CSharpParser.cs


示例5: Visit

            public override object Visit(Switch switchStatement)
            {
                var result = new SwitchStatement ();

                var location = LocationsBag.GetLocations (switchStatement);
                result.AddChild (new CSharpTokenNode (Convert (switchStatement.loc), SwitchStatement.SwitchKeywordRole), SwitchStatement.SwitchKeywordRole);
                if (location != null)
                    result.AddChild (new CSharpTokenNode (Convert (location [0]), Roles.LPar), Roles.LPar);
                if (switchStatement.Expr != null)
                    result.AddChild ((Expression)switchStatement.Expr.Accept (this), Roles.Expression);
                if (location != null && location.Count > 1)
                    result.AddChild (new CSharpTokenNode (Convert (location [1]), Roles.RPar), Roles.RPar);
                if (location != null && location.Count > 2)
                    result.AddChild (new CSharpTokenNode (Convert (location [2]), Roles.LBrace), Roles.LBrace);
                if (switchStatement.Sections != null) {
                    foreach (var section in switchStatement.Sections) {
                        var newSection = new SwitchSection ();
                        if (section.Labels != null) {
                            foreach (var caseLabel in section.Labels) {
                                var newLabel = new CaseLabel ();
                                if (caseLabel.Label != null) {
                                    newLabel.AddChild (new CSharpTokenNode (Convert (caseLabel.Location), CaseLabel.CaseKeywordRole), CaseLabel.CaseKeywordRole);
                                    if (caseLabel.Label != null)
                                        newLabel.AddChild ((Expression)caseLabel.Label.Accept (this), Roles.Expression);
                                    var colonLocation = LocationsBag.GetLocations (caseLabel);
                                    if (colonLocation != null)
                                        newLabel.AddChild (new CSharpTokenNode (Convert (colonLocation [0]), Roles.Colon), Roles.Colon);
                                } else {
                                    newLabel.AddChild (new CSharpTokenNode (Convert (caseLabel.Location), CaseLabel.DefaultKeywordRole), CaseLabel.DefaultKeywordRole);
                                    newLabel.AddChild (new CSharpTokenNode (new TextLocation (caseLabel.Location.Row, caseLabel.Location.Column + "default".Length), Roles.Colon), Roles.Colon);
                                }
                                newSection.AddChild (newLabel, SwitchSection.CaseLabelRole);
                            }
                        }

                        var blockStatement = section.Block;
                        var bodyBlock = new BlockStatement ();
                        int curLocal = 0;
                        AddBlockChildren (bodyBlock, blockStatement, ref curLocal);
                        foreach (var statement in bodyBlock.Statements) {
                            statement.Remove ();
                            newSection.AddChild (statement, Roles.EmbeddedStatement);

                        }
                        result.AddChild (newSection, SwitchStatement.SwitchSectionRole);
                    }
                }

                if (location != null && location.Count > 3) {
                    result.AddChild (new CSharpTokenNode (Convert (location [3]), Roles.RBrace), Roles.RBrace);
                } else {
                    // parser error, set end node to max value.
                    result.AddChild (new ErrorNode (), Roles.Error);
                }

                return result;
            }
开发者ID:kaagati,项目名称:NRefactory,代码行数:57,代码来源:CSharpParser.cs


示例6: PostWalk

 protected internal virtual void PostWalk(SwitchStatement node) { }
开发者ID:JamesTryand,项目名称:IronScheme,代码行数:1,代码来源:Walker.Generated.cs


示例7: LocalRef

        /*private LocalRef CreateLoopVariable(string name)
        {
            LocalRef ret = new LocalRef(name);
            GetScope().AddSymbol(ret);

            return ret;
        }

        private void RemoveLoopVariable(LocalRef var)
        {
            GetScope().RemoveSymbol(var);
        }*/

        private void AddCase(SwitchStatement ss, object label, Statement block)
        {
            ss.cases.Add(new SwitchStatement.Case(label, block));
        }
开发者ID:gitsly,项目名称:CodingSandbox,代码行数:17,代码来源:Parser.user.cs


示例8: Visit

		public virtual void Visit(SwitchStatement.CaseStatement s)
		{
			VisitChildren(s);

			if (s.ArgumentList != null)
				s.ArgumentList.Accept(this);
			if (s.LastExpression != null)
				s.LastExpression.Accept(this);
		}
开发者ID:DinrusGroup,项目名称:DinrusIDE,代码行数:9,代码来源:DefaultDepthFirstVisitor.cs


示例9: SwitchStatement

		public void SwitchStatement()
		{
			SwitchStatement type = new SwitchStatement {
				Expression = new IdentifierExpression("i"),
				SwitchSections = {
					new SwitchSection {
						CaseLabels = {
							new CaseLabel(new PrimitiveExpression(1)),
							new CaseLabel(new PrimitiveExpression(2))
						},
						Statements = {
							new ExpressionStatement(new IdentifierExpression("A").Invoke()),
							new ExpressionStatement(new IdentifierExpression("B").Invoke()),
							new BreakStatement()
						}
					},
					new SwitchSection {
						CaseLabels = {
							new CaseLabel(new PrimitiveExpression(3))
						},
						Statements = {
							new BlockStatement {
								new VariableDeclarationStatement(new PrimitiveType("int"), "a", new PrimitiveExpression(3)),
								new ReturnStatement(new IdentifierExpression("a")),
							}
						}
					},
					new SwitchSection {
						CaseLabels = {
							new CaseLabel()
						},
						Statements = {
							new BreakStatement()
						}
					}
				}};
			
			AssertOutput("switch (i) {\ncase 1:\ncase 2:\n$A ();\n$B ();\n$break;\n" +
			             "case 3: {\n$int a = 3;\n$return a;\n}\n" +
			             "default:\n$break;\n}\n", type);
		}
开发者ID:Gobiner,项目名称:ILSpy,代码行数:41,代码来源:CSharpOutputVisitorTests.cs


示例10: SwitchWithGotoCase

		public void SwitchWithGotoCase()
		{
			SwitchStatement @switch = new SwitchStatement {
				Expression = new PrimitiveExpression(1),
				SwitchSections = {
					new SwitchSection { // case 0:
						CaseLabels = { new CaseLabel(new PrimitiveExpression(0)) },
						Statements = { new BreakStatement() }
					},
					new SwitchSection { // case 1:
						CaseLabels = { new CaseLabel(new PrimitiveExpression(1)) },
						Statements = {
							new ExpressionStatement(new AssignmentExpression(new IdentifierExpression("a"), new PrimitiveExpression(0))),
							new GotoCaseStatement { LabelExpression = new PrimitiveExpression(2) }
						}
					},
					new SwitchSection { // case 2:
						CaseLabels = { new CaseLabel(new PrimitiveExpression(2)) },
						Statements = { new BreakStatement() }
					}
				}};
			
			SwitchSection case0 = @switch.SwitchSections.ElementAt(0);
			SwitchSection case1 = @switch.SwitchSections.ElementAt(1);
			SwitchSection case2 = @switch.SwitchSections.ElementAt(2);
			
			DefiniteAssignmentAnalysis da = CreateDefiniteAssignmentAnalysis(@switch);
			da.Analyze("a");
			Assert.AreEqual(DefiniteAssignmentStatus.PotentiallyAssigned, da.GetStatusBefore(@switch));
			Assert.AreEqual(DefiniteAssignmentStatus.CodeUnreachable, da.GetStatusBefore(case0.Statements.First()));
			Assert.AreEqual(DefiniteAssignmentStatus.PotentiallyAssigned, da.GetStatusBefore(case1.Statements.First()));
			Assert.AreEqual(DefiniteAssignmentStatus.DefinitelyAssigned, da.GetStatusBefore(case2.Statements.First()));
			Assert.AreEqual(DefiniteAssignmentStatus.DefinitelyAssigned, da.GetStatusAfter(@switch));
		}
开发者ID:mono-soc-2012,项目名称:NRefactory,代码行数:34,代码来源:DefiniteAssignmentTests.cs


示例11: VisitSwitchStatement

 public virtual void VisitSwitchStatement(SwitchStatement switchStatement)
 {
     if (this.ThrowException)
     {
         throw (Exception)this.CreateException(switchStatement);
     }
 }
开发者ID:fabriciomurta,项目名称:BridgeUnified,代码行数:7,代码来源:Visitor.Exception.cs


示例12: Visit

        public void Visit(SwitchStatement expression)
        {
            outStream.Write("switch (");
            expression.Expression.Accept(this);
            outStream.WriteLine(") {");

            foreach (var cc in expression.CaseClauses)
            {
                if (cc.IsDefault)
                    outStream.WriteLine("default:");
                else
                {
                    outStream.Write("case ");
                    cc.Expression.Accept(this);
                    outStream.WriteLine(":");
                }

                VisitStatements(cc.Statements);
            }

            outStream.Write("}");
        }
开发者ID:reshadi2,项目名称:mcjs,代码行数:22,代码来源:AstWriter.cs


示例13: actionPerformed

 /**
  * Call back method that must be called as soon as the given <code>
  * SwitchStatement</code> object has been traversed.
  *
  * @param pSwitchStatement  The <code>SwitchStatement</code> object that has
  *                          just been traversed.
  */
 public void actionPerformed(
      SwitchStatement pSwitchStatement)
 {
     // Nothing to do.
 }
开发者ID:smartmobili,项目名称:parsing,代码行数:12,代码来源:TraverseActionAdapter.cs


示例14: performAction

 /**
  * Call back method that must be called when the given <code>
  * SwitchStatement</code> will become the next <i>traverse candidate</i>.
  *
  * @param pSwitchStatement  The <code>SwitchStatement</code> object that
  *                          will become the next <i>traverse candidate</i>.
  */
 public void performAction(
      SwitchStatement pSwitchStatement)
 {
     // Nothing to do.
 }
开发者ID:smartmobili,项目名称:parsing,代码行数:12,代码来源:TraverseActionAdapter.cs


示例15: VisitSwitchStatement

		public override void VisitSwitchStatement(SwitchStatement switchStatement)
		{
			ForceSpacesBefore(switchStatement.LParToken, policy.SpaceBeforeSwitchParentheses);

			ForceSpacesAfter(switchStatement.LParToken, policy.SpacesWithinSwitchParentheses);
			ForceSpacesBefore(switchStatement.RParToken, policy.SpacesWithinSwitchParentheses);

			EnforceBraceStyle(policy.StatementBraceStyle, switchStatement.LBraceToken, switchStatement.RBraceToken);
			VisitChildren(switchStatement);
		}
开发者ID:txdv,项目名称:monodevelop,代码行数:10,代码来源:AstFormattingVisitor.cs


示例16: Exit

 public override void Exit(SwitchStatement node)
 {
     level--;
 }
开发者ID:buunguyen,项目名称:bike,代码行数:4,代码来源:PrintNodeWalker.cs


示例17: Enter

 public virtual bool Enter(SwitchStatement node)
 {
     return true;
 }
开发者ID:buunguyen,项目名称:bike,代码行数:4,代码来源:EnterForWalkerGenerator.cs


示例18: Exit

 public virtual void Exit(SwitchStatement node)
 {
 }
开发者ID:buunguyen,项目名称:bike,代码行数:3,代码来源:EnterForWalkerGenerator.cs


示例19: Walk

 // SwitchStatement
 protected internal virtual bool Walk(SwitchStatement node) { return true; }
开发者ID:JamesTryand,项目名称:IronScheme,代码行数:2,代码来源:Walker.Generated.cs


示例20: VisitSwitchStatement

        public override StringBuilder VisitSwitchStatement(SwitchStatement switchStatement, int data)
        {
            var result = new StringBuilder("switch (").Append(switchStatement.Expression.AcceptVisitor(this, data)).Append(")");

            result.Append(Environment.NewLine + "{");

            foreach (var section in switchStatement.SwitchSections)
                result.Append(Environment.NewLine).Append(Indent(section, section.AcceptVisitor(this, data)));

            result.Append(Environment.NewLine + "}");

            return result;
        }
开发者ID:mono-soc-2011,项目名称:SLSharp,代码行数:13,代码来源:GlslVisitor.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# SwitchStatementSyntax类代码示例发布时间:2022-05-24
下一篇:
C# SwitchSection类代码示例发布时间: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