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


C# BlockStatement.Assign方法代码示例

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


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


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