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


C# Expression.GetRegion方法代码示例

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


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

示例1: GenerateUsingBlock

		private JsBlockStatement GenerateUsingBlock(LocalResolveResult resource, Expression aquisitionExpression, DomRegion tempVariableRegion, JsBlockStatement body) {
			SetRegion(aquisitionExpression.GetRegion());
			var boolType = _compilation.FindType(KnownTypeCode.Boolean);
			var systemIDisposable = _compilation.FindType(KnownTypeCode.IDisposable);
			var disposeMethod = systemIDisposable.GetMethods().Single(m => m.Name == "Dispose");
			var conversions = CSharpConversions.Get(_compilation);

			var aquisitionResolveResult = _resolver.Resolve(aquisitionExpression);
			var compiledAquisition = _expressionCompiler.Compile(aquisitionResolveResult, true);

			var stmts = new List<JsStatement>();
			stmts.AddRange(compiledAquisition.AdditionalStatements);
			stmts.Add(JsStatement.Var(_variables[resource.Variable].Name, MaybeCloneValueType(compiledAquisition.Expression, aquisitionResolveResult, resource.Type)));

			bool isDynamic = resource.Type.Kind == TypeKind.Dynamic;

			if (isDynamic) {
				var newResource = CreateTemporaryVariable(systemIDisposable, tempVariableRegion);
				var castExpr = _expressionCompiler.Compile(new ConversionResolveResult(systemIDisposable, resource, conversions.ExplicitConversion(resource, systemIDisposable)), true);
				stmts.AddRange(castExpr.AdditionalStatements);
				stmts.Add(JsStatement.Var(_variables[newResource].Name, castExpr.Expression));
				resource = new LocalResolveResult(newResource);
			}

			var compiledDisposeCall = _expressionCompiler.Compile(
			                              new CSharpInvocationResolveResult(
			                                  new ConversionResolveResult(systemIDisposable, resource, conversions.ImplicitConversion(resource, systemIDisposable)),
			                                  disposeMethod,
			                                  new ResolveResult[0]
			                              ), false);
			if (compiledDisposeCall.AdditionalStatements.Count > 0)
				_errorReporter.InternalError("Type test cannot return additional statements.");

			JsStatement releaseStmt;
			if (isDynamic) {
				releaseStmt = compiledDisposeCall.Expression;
			}
			else {
				// if (d != null) ((IDisposable)d).Dispose()
				var compiledTest = _expressionCompiler.Compile(new OperatorResolveResult(boolType, ExpressionType.NotEqual, resource, new ConstantResolveResult(resource.Type, null)), true);
				if (compiledTest.AdditionalStatements.Count > 0)
					_errorReporter.InternalError("Null test cannot return additional statements.");
				releaseStmt = resource.Type.IsReferenceType == false && !resource.Type.IsKnownType(KnownTypeCode.NullableOfT) ? (JsStatement)compiledDisposeCall.Expression : JsStatement.If(compiledTest.Expression, compiledDisposeCall.Expression, null);
			}

			stmts.Add(JsStatement.Try(body, null, releaseStmt));

			return JsStatement.Block(stmts);
		}
开发者ID:chenxustu1,项目名称:SaltarelleCompiler,代码行数:49,代码来源:StatementCompiler.cs

示例2: CompileAndAddFieldInitializerToType

 private void CompileAndAddFieldInitializerToType(JsClass jsClass, string fieldName, ITypeDefinition owningType, Expression initializer, bool isStatic)
 {
     if (isStatic) {
         jsClass.StaticInitStatements.AddRange(CreateMethodCompiler().CompileFieldInitializer(initializer.GetRegion(), JsExpression.MemberAccess(_runtimeLibrary.GetScriptType(owningType, TypeContext.UseStaticMember), fieldName), initializer));
     }
     else {
         AddInstanceInitStatements(jsClass, CreateMethodCompiler().CompileFieldInitializer(initializer.GetRegion(), JsExpression.MemberAccess(JsExpression.This, fieldName), initializer));
     }
 }
开发者ID:jack128,项目名称:SaltarelleCompiler,代码行数:9,代码来源:Compiler.cs

示例3: CompileExpression

		private ExpressionCompileResult CompileExpression(Expression expr, CompileExpressionFlags flags) {
			var oldRegion = _errorReporter.Region;
			try {
				_errorReporter.Region = expr.GetRegion();
				var rr = ResolveWithConversion(expr);
				var result = _expressionCompiler.Compile(rr, (flags & CompileExpressionFlags.ReturnValueIsImportant) != 0);
				if (((flags & CompileExpressionFlags.IsAssignmentSource) != 0) && IsMutableValueType(rr.Type)) {
					result.Expression = MaybeCloneValueType(result.Expression, rr, rr.Type);
				}
				return result;
			}
			finally {
				_errorReporter.Region = oldRegion;
			}
		}
开发者ID:chenxustu1,项目名称:SaltarelleCompiler,代码行数:15,代码来源:StatementCompiler.cs

示例4: CompileExpression

		private ExpressionCompileResult CompileExpression(Expression expr, bool returnValueIsImportant) {
			var oldRegion = _errorReporter.Region;
			try {
				_errorReporter.Region = expr.GetRegion();
				return _expressionCompiler.Compile(ResolveWithConversion(expr), returnValueIsImportant);
			}
			finally {
				_errorReporter.Region = oldRegion;
			}
		}
开发者ID:n9,项目名称:SaltarelleCompiler,代码行数:10,代码来源:StatementCompiler.cs

示例5: CheckExpectedType

		bool CheckExpectedType(Expression node)
		{
			IType expectedExpectedType = resolveAllResolver.GetExpectedType(node);
			IType actualExpectedType = resolver.GetExpectedType(node);
			if (expectedExpectedType.Equals(actualExpectedType))
				return true;
			Console.WriteLine("Different expected types for '{0}' at {1} in {2}:", node, node.StartLocation, node.GetRegion().FileName);
			Console.WriteLine(" expected: " + expectedExpectedType);
			Console.WriteLine(" actual:   " + actualExpectedType);
			return false;
		}
开发者ID:KAW0,项目名称:Alter-Native,代码行数:11,代码来源:RandomizedOrderResolverTest.cs

示例6: CheckConversion

		bool CheckConversion(Expression node)
		{
			Conversion expectedConversion = resolveAllResolver.GetConversion(node);
			Conversion actualConversion = resolver.GetConversion(node);
			if (Compare(expectedConversion, actualConversion, typeof(Conversion)))
				return true;
			Console.WriteLine("Different conversions for '{0}' at {1} in {2}:", node, node.StartLocation, node.GetRegion().FileName);
			Console.WriteLine(" expected: " + expectedConversion);
			Console.WriteLine(" actual:   " + actualConversion);
			return false;
		}
开发者ID:KAW0,项目名称:Alter-Native,代码行数:11,代码来源:RandomizedOrderResolverTest.cs

示例7: CompileAndAddFieldInitializerToType

		private void CompileAndAddFieldInitializerToType(JsClass jsClass, string fieldName, ITypeDefinition owningType, Expression initializer, bool isStatic) {
			if (isStatic) {
				jsClass.StaticInitStatements.AddRange(CreateMethodCompiler().CompileFieldInitializer(initializer.GetRegion(), JsExpression.Member(_runtimeLibrary.InstantiateType(Utils.SelfParameterize(owningType), this), fieldName), initializer, owningType));
			}
			else {
				AddInstanceInitStatements(jsClass, CreateMethodCompiler().CompileFieldInitializer(initializer.GetRegion(), JsExpression.Member(JsExpression.This, fieldName), initializer, owningType));
			}
		}
开发者ID:chenxustu1,项目名称:SaltarelleCompiler,代码行数:8,代码来源:Compiler.cs

示例8: CompileExpression

 private ExpressionCompiler.Result CompileExpression(Expression expr, bool returnValueIsImportant)
 {
     return _expressionCompiler.Compile(expr.GetRegion().FileName, expr.StartLocation, ResolveWithConversion(expr), returnValueIsImportant);
 }
开发者ID:arnauddias,项目名称:SaltarelleCompiler,代码行数:4,代码来源:StatementCompiler.cs


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