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


C# Arguments.CastDynamicArgs方法代码示例

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


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

示例1: EmitCallWithInvoke

		protected void EmitCallWithInvoke (EmitContext ec, Expression binder, Arguments arguments, bool isStatement)
		{
			var module = ec.Module;

			var site_container = ec.CreateDynamicSite ();

			BlockContext bc = new BlockContext (ec.MemberContext, null, ec.BuiltinTypes.Void);

			FieldExpr site_field_expr = null;
			StatementExpression s = null;

			// create call site
			var call_site = binder;
			if (call_site != null) {
				// resolve call site
				call_site = call_site.Resolve(bc);

				// create field for call site
				var site_type_decl = call_site.Type;  
				var field = site_container.CreateCallSiteField (new TypeExpression(site_type_decl, loc), loc);
				if (field == null) {
					throw new InvalidOperationException("Could not create call site field");
				}

				// ???
				bool inflate_using_mvar = context_mvars != null && ec.IsAnonymousStoreyMutateRequired;

				// ???
				TypeSpec gt;
				if (inflate_using_mvar || context_mvars == null) {
					gt = site_container.CurrentType;
				} else {
					gt = site_container.CurrentType.MakeGenericType (module, context_mvars.Types);
				}

				// When site container already exists the inflated version has to be
				// updated manually to contain newly created field
				if (gt is InflatedTypeSpec && site_container.AnonymousMethodsCounter > 1) {
					var tparams = gt.MemberDefinition.TypeParametersCount > 0 ? gt.MemberDefinition.TypeParameters : TypeParameterSpec.EmptyTypes;
					var inflator = new TypeParameterInflator (module, gt, tparams, gt.TypeArguments);
					gt.MemberCache.AddMember (field.InflateMember (inflator));
				}

				site_field_expr = new FieldExpr (MemberCache.GetMember (gt, field), loc);

				s = new StatementExpression (new SimpleAssign (site_field_expr, call_site));
			}



			using (ec.With (BuilderContext.Options.OmitDebugInfo, true)) {
				if (s!= null && s.Resolve (bc)) {
					Statement init = new If (new Binary (Binary.Operator.Equality, site_field_expr, new NullLiteral (loc)), s, loc);
					init.Emit (ec);
				}

				// remove dynamics from argument list
				arguments.CastDynamicArgs(bc);

				IDynamicCallSite dynamicCallSite = (IDynamicCallSite)this.binder;
				Expression target = dynamicCallSite.InvokeCallSite(bc, site_field_expr, arguments, type, isStatement);
				if (target != null) 
					target = target.Resolve(bc);

				if (target != null)
				{
					var statement = target as ExpressionStatement;
					if (isStatement && statement != null)
					{
						statement.EmitStatement(ec);
					}
					else
					{
						if (!isStatement && (target.Type != type)) {
							// PlayScript: If doing an invoke, we have to cast the return type to the type expected by the expression..
							target = new Cast(new TypeExpression(type, loc), target, loc).Resolve (bc);
						} 

						target.Emit(ec);
					}
				}
			}

		}
开发者ID:rlfqudxo,项目名称:playscript-mono,代码行数:84,代码来源:dynamic.cs


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