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


C# SwitchSection类代码示例

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


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

示例1: SwitchBlock

 public SwitchBlock(IEmitter emitter, SwitchSection switchSection, string varName, bool isFirst, bool isEnd)
     : base(emitter, switchSection)
 {
     this.Emitter = emitter;
     this.SwitchSection = switchSection;
     varName_ = varName;
     isFirst_ = isFirst;
     isEnd_ = isEnd;
 }
开发者ID:yindongfei,项目名称:bridge.lua,代码行数:9,代码来源:SwitchBlock.cs

示例2: VisitSwitchSection

            public override object VisitSwitchSection(SwitchSection switchSection, object data)
            {
                if(switchSection.CaseLabels.Any(a => a.Expression.IsNull))
                {
                    UnlockWith(switchSection);
                }

                return base.VisitSwitchSection(switchSection, data);
            }
开发者ID:vlad2135,项目名称:strokes,代码行数:9,代码来源:DefaultCaseInSwitchAchievement.cs

示例3: VisitSwitchSection

			public override void VisitSwitchSection (SwitchSection switchSection)
			{
				base.VisitSwitchSection (switchSection);

				if (switchSection.CaseLabels.Count <2)
					return;

				var lastLabel = switchSection.CaseLabels.LastOrNullObject ();
				if (!lastLabel.Expression.IsNull)
					return;
				AddIssue (switchSection.FirstChild.StartLocation, lastLabel.StartLocation,
					ctx.TranslateString ("Remove redundant 'case' label"), scipt => {
						foreach (var label in switchSection.CaseLabels) {
							if (label != lastLabel)
								scipt.Remove (label);
						}
					});
			}
开发者ID:Gobiner,项目名称:ILSpy,代码行数:18,代码来源:RedundantCaseLabelIssue.cs

示例4: SwitchStatement

 public SwitchStatement(
     Exp expTest,
     SwitchSection [] sections
 )
 {
     m_expTest = expTest;
     m_sections = sections;
     
     m_proxy = null;
 }
开发者ID:chenzuo,项目名称:blue,代码行数:10,代码来源:StatementAST.cs

示例5: VisitSwitchSection

		public virtual void VisitSwitchSection (SwitchSection switchSection)
		{
			VisitChildren (switchSection);
		}
开发者ID:modulexcite,项目名称:ICSharpCode.Decompiler-retired,代码行数:4,代码来源:DepthFirstAstVisitor.cs

示例6: 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:RainsSoft,项目名称:playscript-monodevelop,代码行数:57,代码来源:CSharpParser.cs

示例7: VisitSwitchSection

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

示例8: VisitSwitchSection

		public override object VisitSwitchSection(SwitchSection switchSection, object data)
		{
			if (language == SupportedLanguage.VBNet) {
				return VisitBlockStatement(switchSection, data);
			} else {
				return base.VisitSwitchSection(switchSection, data);
			}
		}
开发者ID:mgagne-atman,项目名称:Projects,代码行数:8,代码来源:LookupTableVisitor.cs

示例9: TransformNode

		IEnumerable<Statement> TransformNode(ILNode node)
		{
			if (node is ILLabel) {
				yield return new Ast.LabelStatement { Label = ((ILLabel)node).Name }.WithAnnotation(node.ILRanges);
			} else if (node is ILExpression) {
				AstNode codeExpr = TransformExpression((ILExpression)node);
				if (codeExpr != null) {
					if (codeExpr is Ast.Expression) {
						yield return new Ast.ExpressionStatement { Expression = (Ast.Expression)codeExpr };
					} else if (codeExpr is Ast.Statement) {
						yield return (Ast.Statement)codeExpr;
					} else {
						throw new Exception();
					}
				}
			} else if (node is ILWhileLoop) {
				ILWhileLoop ilLoop = (ILWhileLoop)node;
				Expression expr;
				WhileStatement whileStmt = new WhileStatement() {
					Condition = expr = ilLoop.Condition != null ? (Expression)TransformExpression(ilLoop.Condition) : new PrimitiveExpression(true),
					EmbeddedStatement = TransformBlock(ilLoop.BodyBlock)
				};
				expr.AddAnnotation(ilLoop.ILRanges);
				yield return whileStmt;
			} else if (node is ILCondition) {
				ILCondition conditionalNode = (ILCondition)node;
				bool hasFalseBlock = conditionalNode.FalseBlock.EntryGoto != null || conditionalNode.FalseBlock.Body.Count > 0;
				BlockStatement trueStmt;
				var ifElseStmt = new Ast.IfElseStatement {
					Condition = (Expression)TransformExpression(conditionalNode.Condition),
					TrueStatement = trueStmt = TransformBlock(conditionalNode.TrueBlock),
					FalseStatement = hasFalseBlock ? TransformBlock(conditionalNode.FalseBlock) : null
				};
				ifElseStmt.Condition.AddAnnotation(conditionalNode.ILRanges);
				if (ifElseStmt.FalseStatement == null)
					trueStmt.HiddenEnd = NRefactoryExtensions.CreateHidden(conditionalNode.FalseBlock.GetSelfAndChildrenRecursiveILRanges(), trueStmt.HiddenEnd);
				yield return ifElseStmt;
			} else if (node is ILSwitch) {
				ILSwitch ilSwitch = (ILSwitch)node;
				if (ilSwitch.Condition.InferredType.GetElementType() == ElementType.Boolean && (
					from cb in ilSwitch.CaseBlocks
					where cb.Values != null
					from val in cb.Values
					select val
				).Any(val => val != 0 && val != 1))
				{
					// If switch cases contain values other then 0 and 1, force the condition to be non-boolean
					ilSwitch.Condition.ExpectedType = corLib.Int32;
				}
				SwitchStatement switchStmt = new SwitchStatement() { Expression = (Expression)TransformExpression(ilSwitch.Condition) };
				switchStmt.Expression.AddAnnotation(ilSwitch.ILRanges);
				switchStmt.HiddenEnd = NRefactoryExtensions.CreateHidden(ilSwitch.EndILRanges, switchStmt.HiddenEnd);
				foreach (var caseBlock in ilSwitch.CaseBlocks) {
					SwitchSection section = new SwitchSection();
					if (caseBlock.Values != null) {
						section.CaseLabels.AddRange(caseBlock.Values.Select(i => new CaseLabel() { Expression = AstBuilder.MakePrimitive(i, (ilSwitch.Condition.ExpectedType ?? ilSwitch.Condition.InferredType).ToTypeDefOrRef()) }));
					} else {
						section.CaseLabels.Add(new CaseLabel());
					}
					section.Statements.Add(TransformBlock(caseBlock));
					switchStmt.SwitchSections.Add(section);
				}
				yield return switchStmt;
			} else if (node is ILTryCatchBlock) {
				ILTryCatchBlock tryCatchNode = ((ILTryCatchBlock)node);
				var tryCatchStmt = new Ast.TryCatchStatement();
				tryCatchStmt.TryBlock = TransformBlock(tryCatchNode.TryBlock);
				tryCatchStmt.TryBlock.HiddenStart = NRefactoryExtensions.CreateHidden(tryCatchNode.ILRanges, tryCatchStmt.TryBlock.HiddenStart);
				foreach (var catchClause in tryCatchNode.CatchBlocks) {
					if (catchClause.ExceptionVariable == null
					    && (catchClause.ExceptionType == null || catchClause.ExceptionType.GetElementType() == ElementType.Object))
					{
						tryCatchStmt.CatchClauses.Add(new Ast.CatchClause { Body = TransformBlock(catchClause) }.WithAnnotation(catchClause.StlocILRanges));
					} else {
						tryCatchStmt.CatchClauses.Add(
							new Ast.CatchClause {
								Type = AstBuilder.ConvertType(catchClause.ExceptionType),
								VariableNameToken = catchClause.ExceptionVariable == null ? null : Identifier.Create(catchClause.ExceptionVariable.Name).WithAnnotation(catchClause.ExceptionVariable.IsParameter ? TextTokenType.Parameter : TextTokenType.Local),
								Body = TransformBlock(catchClause)
							}.WithAnnotation(catchClause.ExceptionVariable).WithAnnotation(catchClause.StlocILRanges));
					}
				}
				if (tryCatchNode.FinallyBlock != null)
					tryCatchStmt.FinallyBlock = TransformBlock(tryCatchNode.FinallyBlock);
				if (tryCatchNode.FaultBlock != null) {
					CatchClause cc = new CatchClause();
					cc.Body = TransformBlock(tryCatchNode.FaultBlock);
					cc.Body.Add(new ThrowStatement()); // rethrow
					tryCatchStmt.CatchClauses.Add(cc);
				}
				yield return tryCatchStmt;
			} else if (node is ILFixedStatement) {
				ILFixedStatement fixedNode = (ILFixedStatement)node;
				FixedStatement fixedStatement = new FixedStatement();
				for (int i = 0; i < fixedNode.Initializers.Count; i++) {
					var initializer = fixedNode.Initializers[i];
					Debug.Assert(initializer.Code == ILCode.Stloc);
					ILVariable v = (ILVariable)initializer.Operand;
					VariableInitializer vi;
					fixedStatement.Variables.Add(vi =
//.........这里部分代码省略.........
开发者ID:nakijun,项目名称:dnSpy,代码行数:101,代码来源:AstMethodBodyBuilder.cs

示例10: VisitSwitchSection

		public override object VisitSwitchSection(SwitchSection switchSection, object data)
		{
			// Check if a 'break' should be auto inserted.
			if (switchSection.Children.Count == 0 ||
			    !(switchSection.Children[switchSection.Children.Count - 1] is BreakStatement ||
			      switchSection.Children[switchSection.Children.Count - 1] is ContinueStatement ||
			      switchSection.Children[switchSection.Children.Count - 1] is ThrowStatement ||
			      switchSection.Children[switchSection.Children.Count - 1] is ReturnStatement))
			{
				switchSection.Children.Add(new BreakStatement());
			}
			return base.VisitSwitchSection(switchSection, data);
		}
开发者ID:mgagne-atman,项目名称:Projects,代码行数:13,代码来源:ToCSharpConvertVisitor.cs

示例11: EmbeddedStatement


//.........这里部分代码省略.........
				
			} else if (StartOf(39)) {

#line  2966 "VBNET.ATG" 
				IfElseStatement ifStatement = new IfElseStatement(expr);
				ifStatement.StartLocation = ifStartLocation;
				
				SingleLineStatementList(
#line  2969 "VBNET.ATG" 
ifStatement.TrueStatement);
				if (la.kind == 98) {
					lexer.NextToken();
					if (StartOf(39)) {
						SingleLineStatementList(
#line  2972 "VBNET.ATG" 
ifStatement.FalseStatement);
					}
				}

#line  2974 "VBNET.ATG" 
				ifStatement.EndLocation = t.Location; statement = ifStatement; 
			} else SynErr(276);
		} else if (la.kind == 182) {
			lexer.NextToken();
			if (la.kind == 61) {
				lexer.NextToken();
			}
			Expr(
#line  2977 "VBNET.ATG" 
out expr);
			EndOfStmt();

#line  2978 "VBNET.ATG" 
			List<SwitchSection> selectSections = new List<SwitchSection>();
			Statement block = null;
			
			while (la.kind == 61) {

#line  2982 "VBNET.ATG" 
				List<CaseLabel> caseClauses = null; Location caseLocation = la.Location; 
				lexer.NextToken();
				CaseClauses(
#line  2983 "VBNET.ATG" 
out caseClauses);
				if (
#line  2983 "VBNET.ATG" 
IsNotStatementSeparator()) {
					lexer.NextToken();
				}
				EndOfStmt();

#line  2985 "VBNET.ATG" 
				SwitchSection selectSection = new SwitchSection(caseClauses);
				selectSection.StartLocation = caseLocation;
				
				Block(
#line  2988 "VBNET.ATG" 
out block);

#line  2990 "VBNET.ATG" 
				selectSection.Children = block.Children;
				selectSection.EndLocation = t.EndLocation;
				selectSections.Add(selectSection);
				
			}
开发者ID:mgagne-atman,项目名称:Projects,代码行数:66,代码来源:Parser.cs

示例12: ParseSwitchSection

//-----------------------------------------------------------------------------    
// section -> ('case' exp ':')+ statement
//           |'default' ':' statement    
//-----------------------------------------------------------------------------
    protected SwitchSection ParseSwitchSection()
    {
        Token t = m_lexer.PeekNextToken();
        SwitchSection c;
        
        // Handle 'default' label
        if (t.TokenType == Token.Type.cDefault)
        {
            ConsumeNextToken();
            ReadExpectedToken(Token.Type.cColon);
            //Statement s = ParseStatement();
            Statement s = ParseStatementList();
            c = new SwitchSection(s);
        }
        
        else {
            // Handle 'case' label
            ArrayList al = new ArrayList();
            
            while (t.TokenType == Token.Type.cCase)
            {
                ConsumeNextToken();
                Exp e = ParseExp();
                ReadExpectedToken(Token.Type.cColon);
                al.Add(e);
                t = m_lexer.PeekNextToken();
            }
            
            //Statement stmt = ParseStatement();
            Statement s = ParseStatementList();
            
            Exp [] eList = new Exp[al.Count];
            for(int i = 0; i < eList.Length; i++)
                eList[i] = (Exp) al[i];
            
            c = new SwitchSection(eList, s);
        }
        return c;
    }
开发者ID:chenzuo,项目名称:blue,代码行数:43,代码来源:Parser.cs

示例13: ParseSwitchStatement

//-----------------------------------------------------------------------------
// Parse a Switch-case statement
// --> 'switch' '(' exp ')' '{' body '}'
// body -> section +
//-----------------------------------------------------------------------------
    protected Statement ParseSwitchStatement()
    {
        ReadExpectedToken(Token.Type.cSwitch);
        
        ReadExpectedToken(Token.Type.cLParen);
        Exp expTest = ParseExp();
        ReadExpectedToken(Token.Type.cRParen);
        
        ReadExpectedToken(Token.Type.cLCurly);
    
        // Parse sections
        ArrayList al = new ArrayList();
        
        Token t = m_lexer.PeekNextToken();
        while(t.TokenType != Token.Type.cRCurly)
        {
            SwitchSection section = ParseSwitchSection();    
            al.Add(section);        
            t = m_lexer.PeekNextToken();
        }
        ReadExpectedToken(Token.Type.cRCurly);
    
        
        SwitchSection [] sections = new SwitchSection[al.Count];
        for(int i = 0; i < sections.Length; i++)
            sections[i] = (SwitchSection) al[i];
            
        Statement s = new SwitchStatement(expTest, sections);
        
        return s;
    }
开发者ID:chenzuo,项目名称:blue,代码行数:36,代码来源:Parser.cs

示例14: VisitSwitchSection

		public virtual void VisitSwitchSection(SwitchSection switchSection)
		{
			StartNode(switchSection);
			bool first = true;
			int count = 0;
			foreach (var label in switchSection.CaseLabels) {
				if (count-- <= 0) {
					cancellationToken.ThrowIfCancellationRequested();
					count = CANCEL_CHECK_LOOP_COUNT;
				}
				if (!first) {
					NewLine();
				}
				label.AcceptVisitor(this);
				first = false;
			}
			bool isBlock = switchSection.Statements.Count == 1 && switchSection.Statements.Single() is BlockStatement;
			if (policy.IndentCaseBody && !isBlock) {
				writer.Indent();
			}
			
			if (!isBlock)
				NewLine();

			count = 0;
			foreach (var statement in switchSection.Statements) {
				if (count-- <= 0) {
					cancellationToken.ThrowIfCancellationRequested();
					count = CANCEL_CHECK_LOOP_COUNT;
				}
				statement.AcceptVisitor(this);
			}
			
			if (policy.IndentCaseBody && !isBlock) {
				writer.Unindent();
			}
			
			EndNode(switchSection);
		}
开发者ID:0xd4d,项目名称:NRefactory,代码行数:39,代码来源:CSharpOutputVisitor.cs

示例15: SwitchSections

	void SwitchSections(
#line  1665 "cs.ATG" 
List<SwitchSection> switchSections) {

#line  1667 "cs.ATG" 
		SwitchSection switchSection = new SwitchSection();
		CaseLabel label;
		
		SwitchLabel(
#line  1671 "cs.ATG" 
out label);

#line  1671 "cs.ATG" 
		SafeAdd(switchSection, switchSection.SwitchLabels, label); 

#line  1672 "cs.ATG" 
		compilationUnit.BlockStart(switchSection); 
		while (StartOf(32)) {
			if (la.kind == 55 || la.kind == 63) {
				SwitchLabel(
#line  1674 "cs.ATG" 
out label);

#line  1675 "cs.ATG" 
				if (label != null) {
				if (switchSection.Children.Count > 0) {
					// open new section
					compilationUnit.BlockEnd(); switchSections.Add(switchSection);
					switchSection = new SwitchSection();
					compilationUnit.BlockStart(switchSection);
				}
				SafeAdd(switchSection, switchSection.SwitchLabels, label);
				}
				
			} else {
				Statement();
			}
		}

#line  1687 "cs.ATG" 
		compilationUnit.BlockEnd(); switchSections.Add(switchSection); 
	}
开发者ID:mgagne-atman,项目名称:Projects,代码行数:42,代码来源:Parser.cs


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