switchstatement.cs

来自「全功能c#编译器」· CS 代码 · 共 146 行

CS
146
字号
using System;
using System.Diagnostics;
using System.Collections;
using System.Collections.Generic;

namespace ICSharpCode.CsVbRefactory.Parser.AST 
{
	public class SwitchStatement : BlockStatement
	{
		Expression          switchExpression;
		List<SwitchSection> switchSections;
		
		public Expression SwitchExpression {
			get {
				return switchExpression;
			}
			set {
				switchExpression = value == null ? Expression.Null : value;
			}
		}
		
		public List<SwitchSection> SwitchSections {
			get {
				return switchSections;
			}
			set {
				switchSections =  value == null ? new List<SwitchSection>(1) : value;
			}
		}
		
		public SwitchStatement(Expression switchExpression, List<SwitchSection> switchSections)
		{
			this.SwitchExpression = switchExpression;
			this.SwitchSections   = switchSections;
		}
		
		public SwitchStatement(Expression switchExpression)
		{
			this.SwitchExpression = switchExpression;
			this.switchSections   = new List<SwitchSection>(1);
		}
		
		public override object AcceptVisitor(IASTVisitor visitor, object data)
		{
			return visitor.Visit(this, data);
		}
		
		public override string ToString()
		{
			return String.Format("[SwitchStatement: SwitchExpression={0}, SwitchSections={1}]",
			                     SwitchExpression,
			                     GetCollectionString(SwitchSections));
		}
	}
	
	public class SwitchSection : BlockStatement
	{
		List<CaseLabel> switchLabels = new List<CaseLabel>(1);
		
		public List<CaseLabel> SwitchLabels {
			get {
				return switchLabels;
			}
		}
		
		public override object AcceptVisitor(IASTVisitor visitor, object data)
		{
			return visitor.Visit(this, data);
		}
		
		public override string ToString()
		{
			return String.Format("[SwitchSection: SwitchLabels={0}]",
			                     GetCollectionString(SwitchLabels));
		}
	}
	
	public class CaseLabel : AbstractNode
	{
		Expression         label        = Expression.Null;
		BinaryOperatorType bOp          = BinaryOperatorType.None;
		Expression         toExpression = Expression.Null;
		
		/// <value>null means default case</value>
		public Expression Label {
			get {
				return label;
			}
			set {
				label = value == null ? Expression.Null : value;
			}
		}
		
		public BinaryOperatorType BinaryOperatorType {
			get {
				return bOp;
			}
			set {
				bOp = value;
			}
		}
		
		public Expression ToExpression {
			get {
				return toExpression;
			}
			set {
				toExpression = value == null ? Expression.Null : value;
			}
		}
		
		public CaseLabel(BinaryOperatorType bOp, Expression label)
		{
			this.BinaryOperatorType = bOp;
			this.Label = label;
		}
		
		public CaseLabel(Expression label)
		{
			this.Label = label;
		}
		
		public CaseLabel(Expression label, Expression toExpression)
		{
			this.Label = label;
			this.ToExpression = toExpression;
		}
		
		public CaseLabel()
		{
			this.label = Expression.Null;
		}
		
		public override object AcceptVisitor(IASTVisitor visitor, object data)
		{
			return visitor.Visit(this, data);
		}
		
		public override string ToString()
		{
			return String.Format("[CaseLabel: Label = {0}]",
			                     Label);
		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?