⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vbnetvisitor.cs

📁 c#源代码
💻 CS
📖 第 1 页 / 共 4 页
字号:
			return data;
		}
		
		public override object Visit(EventAddRegion eventAddRegion, object data)
		{
			// should never be called:
			throw new System.NotSupportedException();
		}
		
		public override object Visit(EventRemoveRegion eventRemoveRegion, object data)
		{
			// should never be called:
			throw new System.NotSupportedException();
		}
		
		public override object Visit(ConstructorDeclaration constructorDeclaration, object data)
		{
			DebugOutput(constructorDeclaration);
			AppendNewLine();
			AppendIndentation();
			sourceText.Append(GetModifier(constructorDeclaration.Modifier));
			sourceText.Append("Sub New");
			sourceText.Append("(");
			AppendParameters(constructorDeclaration.Parameters);
			sourceText.Append(")");
			AppendNewLine();
			
			++indentLevel;
			ConstructorInitializer ci = constructorDeclaration.ConstructorInitializer;
			if (ci != null) {
				AppendIndentation();
				if (ci.ConstructorInitializerType == ConstructorInitializerType.Base) {
					sourceText.Append("MyBase.New");
				} else {
					sourceText.Append("MyClass.New");
				}
				sourceText.Append(GetParameters(ci.Arguments));
				AppendNewLine();
			}
			constructorDeclaration.Body.AcceptChildren(this, data);
			--indentLevel;
			
			AppendIndentation();
			sourceText.Append("End Sub");
			AppendNewLine();
			return null;
		}
		
		public override object Visit(DestructorDeclaration destructorDeclaration, object data)
		{
			DebugOutput(destructorDeclaration);
			AppendNewLine();
			AppendIndentation();
			sourceText.Append("Overrides Protected Sub Finalize()");
			AppendNewLine();
			
			++indentLevel;
			destructorDeclaration.Body.AcceptChildren(this, data);
			--indentLevel;
			
			AppendIndentation();
			sourceText.Append("End Sub");
			AppendNewLine();
			return null;
		}
		
		public override object Visit(OperatorDeclaration operatorDeclaration, object data)
		{
			errors.Error(-1, -1, String.Format("Operator overloading cannot be performed"));
			return null;
		}
		
		public override object Visit(IndexerDeclaration indexerDeclaration, object data)
		{
			DebugOutput(indexerDeclaration);
			
			AppendNewLine();
			AppendAttributes(indexerDeclaration.Attributes);
			AppendIndentation();
			sourceText.Append("Default ");
			sourceText.Append(GetModifier(indexerDeclaration.Modifier));
			if (indexerDeclaration.IsReadOnly) {
				sourceText.Append("ReadOnly ");
			} else if (indexerDeclaration.IsWriteOnly) {
				sourceText.Append("WriteOnly ");
			}
			sourceText.Append("Property Blubber(");
			AppendParameters(indexerDeclaration.Parameters);
			sourceText.Append(") As ");
			sourceText.Append(GetTypeString(indexerDeclaration.TypeReference));
			AppendNewLine();
			
			if (indexerDeclaration.GetRegion != null) {
				++indentLevel;
				indexerDeclaration.GetRegion.AcceptVisitor(this, data);
				--indentLevel;
			}
			
			if (indexerDeclaration.SetRegion != null) {
				++indentLevel;
				indexerDeclaration.SetRegion.AcceptVisitor(this, data);
				--indentLevel;
			}
			
			AppendIndentation();
			sourceText.Append("End Property");
			AppendNewLine();
			return null;
		}
		
		public override object Visit(BlockStatement blockStatement, object data)
		{
			DebugOutput(blockStatement);
			blockStatement.AcceptChildren(this, data);
			return null;
		}
		
		public override object Visit(StatementExpression statementExpression, object data)
		{
			DebugOutput(statementExpression);
			AppendIndentation();
			sourceText.Append(statementExpression.Expression.AcceptVisitor(this, statementExpression).ToString());
			AppendNewLine();
			return null;
		}
		
		public override object Visit(LocalVariableDeclaration localVariableDeclaration, object data)
		{
			DebugOutput(localVariableDeclaration);
			foreach (VariableDeclaration localVar in localVariableDeclaration.Variables) {
				AppendIndentation();
				sourceText.Append(GetModifier(localVariableDeclaration.Modifier));
				if ((localVariableDeclaration.Modifier & Modifier.Const) != Modifier.Const) {
					sourceText.Append("Dim ");
				}
				sourceText.Append(localVar.Name);
				ArrayCreateExpression ace = localVar.Initializer as ArrayCreateExpression;
				if (ace != null && (ace.ArrayInitializer == null || ace.ArrayInitializer.CreateExpressions == null)) {
					foreach (ArrayCreationParameter param in ace.Parameters) {
						sourceText.Append("(");
						sourceText.Append(GetExpressionList(param.Expressions));
						sourceText.Append(")");
					}
					sourceText.Append(" As ");
					sourceText.Append(ConvertTypeString(ace.CreateType.Type));
				} else {
					sourceText.Append(" As ");
					sourceText.Append(GetTypeString(localVariableDeclaration.Type));
					if (localVar.Initializer != null) {
						sourceText.Append(" = ");
						sourceText.Append(localVar.Initializer.AcceptVisitor(this, data).ToString());
					}
				}
				AppendNewLine();
			}
			return null;
		}
		
		public override object Visit(EmptyStatement emptyStatement, object data)
		{
			DebugOutput(emptyStatement);
			AppendNewLine();
			return null;
		}
		
		public override object Visit(ReturnStatement returnStatement, object data)
		{
			DebugOutput(returnStatement);
			AppendIndentation();
			sourceText.Append("Return");
			if (returnStatement.ReturnExpression != null) {
				sourceText.Append(" ");
				sourceText.Append(returnStatement.ReturnExpression.AcceptVisitor(this, data).ToString());
			}
			AppendNewLine();
			return null;
		}
		
		public override object Visit(IfStatement ifStatement, object data)
		{
			DebugOutput(ifStatement);
			AppendIndentation();
			InvocationExpression ie = GetEventHandlerRaise(ifStatement);
			
			if (ie == null) {
				sourceText.Append("If ");
				sourceText.Append(ifStatement.Condition.AcceptVisitor(this, data).ToString());
				sourceText.Append(" Then");
				AppendNewLine();
				
				++indentLevel;
				ifStatement.EmbeddedStatement.AcceptVisitor(this, data);
				--indentLevel;
				
				AppendIndentation();
				sourceText.Append("End If");
				AppendNewLine();
			} else {
				sourceText.Append("RaiseEvent ");
				sourceText.Append(ie.AcceptVisitor(this, data));
				AppendNewLine();
			}
			return null;
		}
		
		public override object Visit(IfElseStatement ifElseStatement, object data)
		{
			DebugOutput(ifElseStatement);
			AppendIndentation();
			sourceText.Append("If ");
			sourceText.Append(ifElseStatement.Condition.AcceptVisitor(this, data).ToString());
			sourceText.Append(" Then");
			AppendNewLine();
			
			++indentLevel;
			ifElseStatement.EmbeddedStatement.AcceptVisitor(this, data);
			--indentLevel;
			
			AppendIndentation();
			sourceText.Append("Else");
			AppendNewLine();
			
			++indentLevel;
			ifElseStatement.EmbeddedElseStatement.AcceptVisitor(this, data);
			--indentLevel;
			
			AppendIndentation();
			sourceText.Append("End If");
			AppendNewLine();
			return null;
		}
		
		public override object Visit(WhileStatement whileStatement, object data)
		{
			DebugOutput(whileStatement);
			AppendIndentation();
			sourceText.Append("While ");
			sourceText.Append(whileStatement.Condition.AcceptVisitor(this, data).ToString());
			AppendNewLine();
			
			++indentLevel;
			whileStatement.EmbeddedStatement.AcceptVisitor(this, data);
			--indentLevel;
			
			AppendIndentation();
			sourceText.Append("End While");
			AppendNewLine();
			return null;
		}
		
		public override object Visit(DoWhileStatement doWhileStatement, object data)
		{
			DebugOutput(doWhileStatement);
			AppendIndentation();
			sourceText.Append("Do");
			AppendNewLine();
			
			++indentLevel;
			doWhileStatement.EmbeddedStatement.AcceptVisitor(this, data);
			--indentLevel;
			
			AppendIndentation();
			sourceText.Append("Loop While ");
			sourceText.Append(doWhileStatement.Condition.AcceptVisitor(this, data).ToString());
			AppendNewLine();
			return null;
		}
		
		public override object Visit(ForStatement forStatement, object data)
		{
			DebugOutput(forStatement);
			if (forStatement.Initializers != null) {
				foreach (object o in forStatement.Initializers) {
					if (o is Expression) {
						Expression expr = (Expression)o;
						AppendIndentation();
						sourceText.Append(expr.AcceptVisitor(this, data).ToString());
						AppendNewLine();
					}
					if (o is Statement) {
						((Statement)o).AcceptVisitor(this, data);
					}
				}
			}
			AppendIndentation();
			sourceText.Append("While ");
			if (forStatement.Condition == null) {
				sourceText.Append("True ");
			} else {
				sourceText.Append(forStatement.Condition.AcceptVisitor(this, data).ToString());
			}
			AppendNewLine();
			
			++indentLevel;
			forStatement.EmbeddedStatement.AcceptVisitor(this, data);
			if (forStatement.Iterator != null) {
				foreach (Statement stmt in forStatement.Iterator) {
					stmt.AcceptVisitor(this, data);
				}
			}
			--indentLevel;
			
			AppendIndentation();
			sourceText.Append("End While");
			AppendNewLine();
			return null;
		}
		
		public override object Visit(LabelStatement labelStatement, object data)
		{
			DebugOutput(labelStatement);
			AppendIndentation();
			sourceText.Append(labelStatement.Label);
			sourceText.Append(":");
			AppendNewLine();
			return null;
		}
		
		public override object Visit(GotoStatement gotoStatement, object data)
		{
			DebugOutput(gotoStatement);
			AppendIndentation();
			sourceText.Append("Goto ");
			sourceText.Append(gotoStatement.Label);
			AppendNewLine();
			return null;
		}
		
		public override object Visit(SwitchStatement switchStatement, object data)
		{
			DebugOutput(switchStatement);
			AppendIndentation();
			sourceText.Append("Select ");
			sourceText.Append(switchStatement.SwitchExpression.AcceptVisitor(this, data).ToString());
			AppendNewLine();
			foreach (SwitchSection section in switchStatement.SwitchSections) {
				AppendIndentation();
				sourceText.Append("Case ");
				
				for (int i = 0; i < section.SwitchLabels.Count; ++i) {
					Expression label = (Expression)section.SwitchLabels[i];
					if (label == null) {
						sourceText.Append("Else");
						continue;
					}
					sourceText.Append(label.AcceptVisitor(this, data));
					if (i + 1 < section.SwitchLabels.Count) {
						sourceText.Append(", ");
					}
				}
				AppendNewLine();
				
				++indentLevel;
				section.AcceptVisitor(this, data);
				--indentLevel;
			}
			AppendIndentation();
			sourceText.Append("End Select ");
			AppendNewLine();
			return null;
		}
		
		public override object Visit(BreakStatement breakStatement, object data)
		{
			DebugOutput(breakStatement);
			AppendIndentation();
			sourceText.Append("' break");
			AppendNewLine();
			return null;
		}
		
		public override object Visit(ContinueStatement continueStatement, object data)
		{
			DebugOutput(continueStatement);
			AppendIndentation();
			sourceText.Append("' continue");
			AppendNewLine();
			return null;
		}
		
		public override object Visit(GotoCaseStatement gotoCaseStatement, object data)
		{
			DebugOutput(gotoCaseStatement);
			AppendIndentation();
			sourceText.Append("' goto case ");
			if (gotoCaseStatement.CaseExpression == null) {
				sourceText.Append("default");
			} else {
				sourceText.Append(gotoCaseStatement.CaseExpression.AcceptVisitor(this, data));
			}
			AppendNewLine();
			return null;
		}
		
		public override object Visit(ForeachStatement foreachStatement, object data)
		{
			DebugOutput(foreachStatement);
			AppendIndentation();
			sourceText.Append("For Each ");
			sourceText.Append(foreachStatement.VariableName);
			sourceText.Append(" As ");
			sourceText.Append(this.GetTypeString(foreachStatement.TypeReference));
			sourceText.Append(" In ");
			sourceText.Append(foreachStatement.Expression.AcceptVisitor(this, data));
			AppendNewLine();
			
			++indentLevel;
			foreachStatement.EmbeddedStatement.AcceptVisitor(this, data);
			--indentLevel;
			
			AppendIndentation();
			sourceText.Append("Next");
			AppendNewLine();
			return null;
		}
		
		public override object Visit(LockStatement lockStatement, object data)
		{
			DebugOutput(lockStatement);
			AppendIndentation();
			sourceText.Append("SyncLock ");
			sourceText.Append(lockStatement.LockExpression.AcceptVisitor(this, data));
			AppendNewLine();
			
			++indentLevel;
			lockStatement.EmbeddedStatement.AcceptVisitor(this, data);
			--indentLevel;
			
			AppendIndentation();
			sourceText.Append("End SyncLock");
			AppendNewLine();
			return null;
		}
		
		public override object Visit(UsingStatement usingStatement, object data)
		{
			DebugOutput(usingStatement);
			// TODO : anything like this ?
			AppendIndentation();
			sourceText.Append("' Using ");AppendNewLine();
			usingStatement.UsingStmnt.AcceptVisitor(this, data);
			AppendIndentation();

⌨️ 快捷键说明

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