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


C# BlockStatement.Return方法代码示例

本文整理汇总了C#中ICSharpCode.NRefactory.Ast.BlockStatement.Return方法的典型用法代码示例。如果您正苦于以下问题:C# BlockStatement.Return方法的具体用法?C# BlockStatement.Return怎么用?C# BlockStatement.Return使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ICSharpCode.NRefactory.Ast.BlockStatement的用法示例。


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

示例1: InitStaticVariable

		INode InitStaticVariable(string initFieldName, string variableName, Expression initializer, TypeDeclaration typeDeclaration)
		{
			const string helperMethodName = "InitStaticVariableHelper";
			
			if (typeDeclaration != null) {
				if (!typeDeclaration.Children.OfType<MethodDeclaration>().Any(m => m.Name == helperMethodName)) {
					// add helper method
					var helperMethod = new MethodDeclaration {
						Name = helperMethodName,
						Modifier = Modifiers.Static,
						TypeReference = new TypeReference("System.Boolean", true),
						Parameters = {
							new ParameterDeclarationExpression(new TypeReference("Microsoft.VisualBasic.CompilerServices.StaticLocalInitFlag"), "flag")
						},
						Body = new BlockStatement()
					};
					BlockStatement trueBlock = new BlockStatement();
					BlockStatement elseIfBlock = new BlockStatement();
					BlockStatement falseBlock = new BlockStatement();
					helperMethod.Body.AddStatement(
						new IfElseStatement(ExpressionBuilder.Identifier("flag").Member("State").Operator(BinaryOperatorType.Equality, new PrimitiveExpression(0))) {
							TrueStatement = { trueBlock },
							ElseIfSections = {
								new ElseIfSection(ExpressionBuilder.Identifier("flag").Member("State").Operator(BinaryOperatorType.Equality, new PrimitiveExpression(2)), elseIfBlock)
							},
							FalseStatement = { falseBlock }
						});
					trueBlock.Assign(ExpressionBuilder.Identifier("flag").Member("State"), new PrimitiveExpression(2));
					trueBlock.Return(new PrimitiveExpression(true));
					elseIfBlock.Throw(new TypeReference("Microsoft.VisualBasic.CompilerServices.IncompleteInitialization").New());
					falseBlock.Return(new PrimitiveExpression(false));
					typeDeclaration.AddChild(helperMethod);
				}
			}
			
			BlockStatement tryBlock = new BlockStatement();
			BlockStatement ifTrueBlock = new BlockStatement();
			tryBlock.AddStatement(new IfElseStatement(ExpressionBuilder.Identifier(helperMethodName).Call(ExpressionBuilder.Identifier(initFieldName)), ifTrueBlock));
			ifTrueBlock.Assign(ExpressionBuilder.Identifier(variableName), initializer);
			
			BlockStatement finallyBlock = new BlockStatement();
			finallyBlock.Assign(ExpressionBuilder.Identifier(initFieldName).Member("State"), new PrimitiveExpression(1));
			
			BlockStatement lockBlock = new BlockStatement();
			lockBlock.AddStatement(new TryCatchStatement(tryBlock, null, finallyBlock));
			return new LockStatement(ExpressionBuilder.Identifier(initFieldName), lockBlock);
		}
开发者ID:XQuantumForceX,项目名称:Reflexil,代码行数:47,代码来源:ToCSharpConvertVisitor.cs

示例2: ReplaceAllFunctionAssignments

		void ReplaceAllFunctionAssignments(BlockStatement block, string functionName, TypeReference typeReference)
		{
			ReturnStatementForFunctionAssignment visitor = new ReturnStatementForFunctionAssignment(functionName);
			block.AcceptVisitor(visitor, null);
			if (visitor.expressionsToReplace.Count == 1 && !visitor.hasExit && IsAssignmentTo(block.Children.Last(), functionName)) {
				Expression returnValue = GetAssignmentFromStatement(block.Children.Last()).Right;
				block.Children.RemoveAt(block.Children.Count - 1);
				block.Return(returnValue);
			} else {
				if (visitor.expressionsToReplace.Count > 0) {
					foreach (var expr in visitor.expressionsToReplace) {
						expr.Identifier = FunctionReturnValueName;
					}
					Expression init;
					init = ExpressionBuilder.CreateDefaultValueForType(typeReference);
					block.Children.Insert(0, new LocalVariableDeclaration(new VariableDeclaration(FunctionReturnValueName, init, typeReference)));
					block.Children[0].Parent = block;
					block.Return(new IdentifierExpression(FunctionReturnValueName));
				}
			}
		}
开发者ID:Altaxo,项目名称:Altaxo,代码行数:21,代码来源:VBNetConstructsConvertVisitor.cs


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