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


C# Delegate.CreateType方法代码示例

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


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

示例1: CreateSiteType

        TypeExpr CreateSiteType(CompilerContext ctx, Arguments arguments, int dyn_args_count, bool is_statement)
        {
            int default_args = is_statement ? 1 : 2;

            bool has_ref_out_argument = false;
            FullNamedExpression[] targs = new FullNamedExpression[dyn_args_count + default_args];
            targs [0] = new TypeExpression (TypeManager.call_site_type, loc);
            for (int i = 0; i < dyn_args_count; ++i) {
                TypeSpec arg_type;
                Argument a = arguments [i];
                if (a.Type == TypeManager.null_type)
                    arg_type = TypeManager.object_type;
                else
                    arg_type = a.Type;

                if (a.ArgType == Argument.AType.Out || a.ArgType == Argument.AType.Ref)
                    has_ref_out_argument = true;

                targs [i + 1] = new TypeExpression (arg_type, loc);
            }

            TypeExpr del_type = null;
            if (!has_ref_out_argument) {
                string d_name = is_statement ? "Action" : "Func";

                TypeSpec t = TypeManager.CoreLookupType (ctx, "System", d_name, dyn_args_count + default_args, MemberKind.Delegate, false);
                if (t != null) {
                    if (!is_statement)
                        targs [targs.Length - 1] = new TypeExpression (type, loc);

                    del_type = new GenericTypeExpr (t, new TypeArguments (targs), loc);
                }
            }

            //
            // Create custom delegate when no appropriate predefined one is found
            //
            if (del_type == null) {
                TypeSpec rt = is_statement ? TypeManager.void_type : type;
                Parameter[] p = new Parameter [dyn_args_count + 1];
                p[0] = new Parameter (targs [0], "p0", Parameter.Modifier.NONE, null, loc);

                for (int i = 1; i < dyn_args_count + 1; ++i)
                    p[i] = new Parameter (targs[i], "p" + i.ToString ("X"), arguments[i - 1].Modifier, null, loc);

                TypeContainer parent = CreateSiteContainer ();
                Delegate d = new Delegate (parent.NamespaceEntry, parent, new TypeExpression (rt, loc),
                    Modifiers.INTERNAL | Modifiers.COMPILER_GENERATED,
                    new MemberName ("Container" + container_counter++.ToString ("X")),
                    new ParametersCompiled (ctx, p), null);

                d.CreateType ();
                d.DefineType ();
                d.Define ();
                d.Emit ();

                parent.AddDelegate (d);
                del_type = new TypeExpression (d.Definition, loc);
            }

            TypeExpr site_type = new GenericTypeExpr (TypeManager.generic_call_site_type, new TypeArguments (del_type), loc);
            return site_type;
        }
开发者ID:speier,项目名称:shake,代码行数:63,代码来源:dynamic.cs

示例2: EmitCall


//.........这里部分代码省略.........

					del_type = new GenericTypeExpr (te.Type, new TypeArguments (targs), loc);
					if (targs_for_instance != null)
						del_type_instance_access = new GenericTypeExpr (te.Type, new TypeArguments (targs_for_instance), loc);
					else
						del_type_instance_access = del_type;
				}
			}

			//
			// Create custom delegate when no appropriate predefined delegate has been found
			//
			Delegate d;
			if (del_type == null) {
				TypeSpec rt = isStatement ? ec.BuiltinTypes.Void : type;
				Parameter[] p = new Parameter[dyn_args_count + 1];
				p[0] = new Parameter (targs[0], "p0", Parameter.Modifier.NONE, null, loc);

				var site = ec.CreateDynamicSite ();
				int index = site.Types == null ? 0 : site.Types.Count;

				if (mutator != null)
					rt = mutator.Mutate (rt);

				for (int i = 1; i < dyn_args_count + 1; ++i) {
					p[i] = new Parameter (targs[i], "p" + i.ToString ("X"), arguments[i - 1].Modifier, null, loc);
				}

				d = new Delegate (site.NamespaceEntry, site, new TypeExpression (rt, loc),
					Modifiers.INTERNAL | Modifiers.COMPILER_GENERATED,
					new MemberName ("Container" + index.ToString ("X")),
					new ParametersCompiled (p), null);

				d.CreateType ();
				d.DefineType ();
				d.Define ();
				d.Emit ();

				site.AddDelegate (d);
				del_type = new TypeExpression (d.CurrentType, loc);
				if (targs_for_instance != null) {
					del_type_instance_access = null;
				} else {
					del_type_instance_access = del_type;
				}
			} else {
				d = null;
			}

			var site_type_decl = new GenericTypeExpr (module.PredefinedTypes.CallSiteGeneric.TypeSpec, new TypeArguments (del_type), loc);
			var field = site_container.CreateCallSiteField (site_type_decl, loc);
			if (field == null)
				return;

			if (del_type_instance_access == null) {
				var dt = d.CurrentType.DeclaringType.MakeGenericType (module, context_mvars.Select (l => l.Type).ToArray ());
				del_type_instance_access = new TypeExpression (MemberCache.GetMember (dt, d.CurrentType), loc);
			}

			FullNamedExpression instanceAccessExprType = new GenericTypeExpr (module.PredefinedTypes.CallSiteGeneric.TypeSpec,
				new TypeArguments (del_type_instance_access), loc);

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

			instanceAccessExprType = instanceAccessExprType.ResolveAsType (bc);
			if (instanceAccessExprType == null)
开发者ID:JustasB,项目名称:cudafy,代码行数:67,代码来源:dynamic.cs

示例3: CreateSiteType

        TypeExpr CreateSiteType(EmitContext ec, Arguments arguments, int dyn_args_count, bool is_statement)
        {
            int default_args = is_statement ? 1 : 2;
            var module = ec.Module;

            bool has_ref_out_argument = false;
            var targs = new TypeExpression[dyn_args_count + default_args];
            targs [0] = new TypeExpression (module.PredefinedTypes.CallSite.TypeSpec, loc);
            for (int i = 0; i < dyn_args_count; ++i) {
                Argument a = arguments [i];
                if (a.ArgType == Argument.AType.Out || a.ArgType == Argument.AType.Ref)
                    has_ref_out_argument = true;

                var t = a.Type;

                // Convert any internal type like dynamic or null to object
                if (t.Kind == MemberKind.InternalCompilerType)
                    t = TypeManager.object_type;

                targs [i + 1] = new TypeExpression (t, loc);
            }

            TypeExpr del_type = null;
            if (!has_ref_out_argument) {
                string d_name = is_statement ? "Action" : "Func";

                TypeExpr te = null;
                Namespace type_ns = module.GlobalRootNamespace.GetNamespace ("System", true);
                if (type_ns != null) {
                    te = type_ns.LookupType (module, d_name, dyn_args_count + default_args, true, Location.Null);
                }

                if (te != null) {
                    if (!is_statement)
                        targs [targs.Length - 1] = new TypeExpression (type, loc);

                    del_type = new GenericTypeExpr (te.Type, new TypeArguments (targs), loc);
                }
            }

            //
            // Create custom delegate when no appropriate predefined one is found
            //
            if (del_type == null) {
                TypeSpec rt = is_statement ? TypeManager.void_type : type;
                Parameter[] p = new Parameter [dyn_args_count + 1];
                p[0] = new Parameter (targs [0], "p0", Parameter.Modifier.NONE, null, loc);

                var site = ec.CreateDynamicSite ();
                int index = site.Types == null ? 0 : site.Types.Count;

                if (site.Mutator != null)
                    rt = site.Mutator.Mutate (rt);

                for (int i = 1; i < dyn_args_count + 1; ++i) {
                    var t = targs[i];
                    if (site.Mutator != null)
                        t.Type = site.Mutator.Mutate (t.Type);

                    p[i] = new Parameter (t, "p" + i.ToString ("X"), arguments[i - 1].Modifier, null, loc);
                }

                Delegate d = new Delegate (site.NamespaceEntry, site, new TypeExpression (rt, loc),
                    Modifiers.INTERNAL | Modifiers.COMPILER_GENERATED,
                    new MemberName ("Container" + index.ToString ("X")),
                    new ParametersCompiled (p), null);

                d.CreateType ();
                d.DefineType ();
                d.Define ();
                d.Emit ();

                var inflated = site.AddDelegate (d);
                del_type = new TypeExpression (inflated, loc);
            }

            TypeExpr site_type = new GenericTypeExpr (module.PredefinedTypes.CallSiteGeneric.TypeSpec, new TypeArguments (del_type), loc);
            return site_type;
        }
开发者ID:RainsSoft,项目名称:MonoCompilerAsAService,代码行数:79,代码来源:dynamic.cs

示例4: CreateSiteType

		TypeExpr CreateSiteType (EmitContext ec, Arguments arguments, int dyn_args_count, bool is_statement)
		{
			int default_args = is_statement ? 1 : 2;

			bool has_ref_out_argument = false;
			var targs = new TypeExpression[dyn_args_count + default_args];
			targs [0] = new TypeExpression (TypeManager.call_site_type, loc);
			for (int i = 0; i < dyn_args_count; ++i) {
				Argument a = arguments [i];
				if (a.ArgType == Argument.AType.Out || a.ArgType == Argument.AType.Ref)
					has_ref_out_argument = true;

				targs [i + 1] = new TypeExpression (a.Type, loc);
			}

			TypeExpr del_type = null;
			if (!has_ref_out_argument) {
				string d_name = is_statement ? "Action" : "Func";

				TypeSpec t = TypeManager.CoreLookupType (ec.MemberContext.Compiler, "System", d_name, dyn_args_count + default_args, MemberKind.Delegate, false);
				if (t != null) {
					if (!is_statement)
						targs [targs.Length - 1] = new TypeExpression (type, loc);

					del_type = new GenericTypeExpr (t, new TypeArguments (targs), loc);
				}
			}

			//
			// Create custom delegate when no appropriate predefined one is found
			//
			if (del_type == null) {
				TypeSpec rt = is_statement ? TypeManager.void_type : type;
				Parameter[] p = new Parameter [dyn_args_count + 1];
				p[0] = new Parameter (targs [0], "p0", Parameter.Modifier.NONE, null, loc);

				var site = ec.CreateDynamicSite ();
				int index = site.Types == null ? 0 : site.Types.Count;

				if (site.Mutator != null)
					rt = site.Mutator.Mutate (rt);

				for (int i = 1; i < dyn_args_count + 1; ++i) {
					var t = targs[i];
					if (site.Mutator != null)
						t.Type = site.Mutator.Mutate (t.Type);

					p[i] = new Parameter (t, "p" + i.ToString ("X"), arguments[i - 1].Modifier, null, loc);
				}

				Delegate d = new Delegate (site.NamespaceEntry, site, new TypeExpression (rt, loc),
					Modifiers.INTERNAL | Modifiers.COMPILER_GENERATED,
					new MemberName ("Container" + index.ToString ("X")),
					new ParametersCompiled (p), null);

				d.CreateType ();
				d.DefineType ();
				d.Define ();
				d.Emit ();

				var inflated = site.AddDelegate (d);
				del_type = new TypeExpression (inflated, loc);
			}

			TypeExpr site_type = new GenericTypeExpr (TypeManager.generic_call_site_type, new TypeArguments (del_type), loc);
			return site_type;
		}
开发者ID:cthrax,项目名称:mono,代码行数:67,代码来源:dynamic.cs


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