• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Emit.MethodBuilder类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中System.Reflection.Emit.MethodBuilder的典型用法代码示例。如果您正苦于以下问题:C# MethodBuilder类的具体用法?C# MethodBuilder怎么用?C# MethodBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



MethodBuilder类属于System.Reflection.Emit命名空间,在下文中一共展示了MethodBuilder类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: InjectableConstructorArg

 public InjectableConstructorArg(Type propertyType, string name, MethodBuilder getter, MethodBuilder setter)
 {
     PropertyType = propertyType;
     Name = name;
     Getter = getter;
     Setter = setter;
 }
开发者ID:DivineInject,项目名称:DivineInject,代码行数:7,代码来源:InjectableConstructorArg.cs


示例2: GenCode

        public override void GenCode(TypeBuilder tb, MethodBuilder mb, ILGenerator cg)
        {
            Type type = Type.EmptyTypes.GetType();

            for (int i = 0; i < Compiler.Types.Count; i++)
                if (Compiler.Types[i].name == Expr.ReturnType.Name)
                    type = Compiler.SearchType(Compiler.Types[i].typeArray);

            if (assign)
            {
                assign = false;
                LocalBuilder local = cg.DeclareLocal(type);
                cg.Emit(OpCodes.Stloc, local);
                Expr.GenCode(tb, mb, cg);//pone el array, luego el index y luego el valor para hacer stelem
                Index.GenCode(tb, mb, cg);
                cg.Emit(OpCodes.Ldloc, local);
                cg.Emit(OpCodes.Stelem, type);
            }
            else
            {
                Expr.GenCode(tb, mb, cg);
                Index.GenCode(tb, mb, cg);
                cg.Emit(OpCodes.Ldelem, type);
            }
        }
开发者ID:oisbel,项目名称:TigerCompiler,代码行数:25,代码来源:ElemArrayNode.cs


示例3: Generate

        public static void Generate(
            TypeBuilder typeBuilder,
            EventMetadata eventMetadata, 
            MethodBuilder addMethod,
            MethodBuilder removeMethod,
            MethodBuilder raiseMethod)
        {
            var @event = typeBuilder.DefineEvent(
                eventMetadata.Name,
                eventMetadata.EventAttributes,
                eventMetadata.EventHandlerType);

            if (addMethod != null)
            {
                @event.SetAddOnMethod(addMethod);
            }

            if (removeMethod != null)
            {
                @event.SetRemoveOnMethod(removeMethod);
            }

            if (raiseMethod != null)
            {
                @event.SetRaiseMethod(raiseMethod);
            }
        }
开发者ID:bradleyjford,项目名称:inception,代码行数:27,代码来源:EventGenerator.cs


示例4: EmitEmptyImplementation

 private static void EmitEmptyImplementation( MethodBuilder vM, Type returnType, ParameterInfo[] parameters )
 {
     ILGenerator gVM = vM.GetILGenerator();
     for( int i = 0; i < parameters.Length; ++i )
     {
         // DefineParameter use 0 for the return parameter.
         ParameterInfo param = parameters[i];
         vM.DefineParameter( i + 1, param.Attributes, param.Name );
         if( param.IsOut )
         {
             Debug.Assert( param.ParameterType.IsByRef, "'Out' is just an attribute on 'by ref' parameters (unfortunate for covariance support)." );
             gVM.StoreDefaultValueForOutParameter( param );
         }
     }
     if( returnType != typeof( void ) )
     {
         if( returnType.GetTypeInfo().IsValueType )
         {
             LocalBuilder retValue = gVM.DeclareLocal( returnType );
             gVM.Emit( OpCodes.Ldloca_S, retValue.LocalIndex );
             gVM.Emit( OpCodes.Initobj, returnType );
             gVM.LdLoc( retValue );
         }
         else
         {
             gVM.Emit( OpCodes.Ldnull );
         }
     }
     gVM.Emit( OpCodes.Ret );
 }
开发者ID:Invenietis,项目名称:ck-core,代码行数:30,代码来源:EmitHelper.cs


示例5: CreateMethodBuilder

 private void CreateMethodBuilder()
 {
     methodBuilder = typeBuilder.DefineMethod(
         "DynamicMethod", MethodAttributes.Public | MethodAttributes.Static, typeof(object), new Type[] { typeof(object), typeof(object[]) });
     methodBuilder.InitLocals = true;
     ilGenerator = methodBuilder.GetILGenerator();
 }
开发者ID:seesharper,项目名称:LightProxy,代码行数:7,代码来源:MethodBuilderMethodSkeleton.cs


示例6: CreateMethodBuilder

 private void CreateMethodBuilder(Type returnType, Type[] parameterTypes)
 {
     methodBuilder = typeBuilder.DefineMethod(
         "DynamicMethod", MethodAttributes.Public | MethodAttributes.Static, returnType, parameterTypes);
     methodBuilder.InitLocals = true;
     emitter = new Emitter(methodBuilder.GetILGenerator(), parameterTypes);
 }
开发者ID:vitamink,项目名称:LightInject,代码行数:7,代码来源:MethodBuilderMethodSkeleton.cs


示例7: CreateContinueMethod

        private void CreateContinueMethod(MethodInfo method, MethodBuilder continueMethod, int position, Type[] parameters, int count)
        {
            var generator = continueMethod.GetILGenerator();

            // Store array in temp0
            generator.DeclareLocal(typeof (object[]));
            generator.LoadArgument(1);
            generator.StashTemporaryVariable(0);

            // Push backing object onto the stack
            generator.LoadField(backingObject);

            // Push each of the arguments passed in onto the stack
            for (int i = 0; i < count; i++)
            {
                generator.LoadTemporaryVariable(0);
                generator.LoadInteger(i);
                generator.Emit(OpCodes.Ldelem_Ref);
                generator.MaybeUnBox(parameters[i]);
            }

            // Delegate to backing object
            generator.Execute(method);

            // Convert the returned value to an object
            if (method.ReturnType == typeof(void))
                generator.LoadNull();
            else
                generator.MaybeBox(method.ReturnType);

            // Return
            generator.Emit(OpCodes.Ret);
        }
开发者ID:gja,项目名称:LightProxy,代码行数:33,代码来源:ProxyBuilder.cs


示例8: GenerateFunction

        private void GenerateFunction(TypeBuilder typeBuilder, out MethodBuilder methodBuilder)
        {
            methodBuilder = null;
            ProgramDeclBlock pdb = this.expr as ProgramDeclBlock;
            if (pdb != null)
            {
                foreach (var function in pdb.Statements)
                {
                    var functionDecl = function as BlockDeclExpr;
                    if (functionDecl != null)
                    {
                        bool isMain = functionDecl.IsMain;
                        var parameters = functionDecl.Parameters;

                        Expr mainFunctionParameters = null;

                        if (isMain)
                        {
                            mainFunctionParameters =
                                GenerateMainMethod(
                                    typeBuilder,
                                    functionDecl,
                                    parameters,
                                    mainFunctionParameters,
                                    out methodBuilder);
                        }
                    }
                }
            }
        }
开发者ID:donreamey,项目名称:vmeex,代码行数:30,代码来源:GenerateIL.cs


示例9: IncLevel

        public void IncLevel(int i, string procId)
        {
            Debug.WriteLine(String.Format("Generator: IncLevel({0},{1})", i, procId));

            if(i > 0)
                currentMethodBuilder = currentType.DefineMethod(procId, MethodAttributes.Static, typeof(void), System.Type.EmptyTypes);
        }
开发者ID:adbrowne,项目名称:abcm,代码行数:7,代码来源:Generator.cs


示例10: EmitMethodBody

		private static void EmitMethodBody (MethodBuilder methodBuilder, MethodInfo methodInfo, String message)
		{
			Type returnType = methodInfo.ReturnType;
			ILGenerator generator = methodBuilder.GetILGenerator ();
			ParameterInfo[] parameterInfos = methodInfo.GetParameters ();

			if (returnType == typeof(void)) {
				MethodInfo sendMessageInvoker = EmitInfos.OBJECTIVECRUNTIME_SENDMESSAGE_VOID_ARGS;

				// Makes the actual call
				generator.Emit (OpCodes.Ldarg_0);
				generator.Emit (OpCodes.Ldstr, message);
				EmitParametersAsArrayOnStack (generator, parameterInfos);
				generator.Emit (OpCodes.Call, sendMessageInvoker);

				generator.Emit (OpCodes.Ret);
			} else {
				MethodInfo sendMessageInvoker = EmitInfos.OBJECTIVECRUNTIME_SENDMESSAGE_ARGS_GENERIC.MakeGenericMethod (returnType);

				// Makes the actual call
				generator.Emit (OpCodes.Ldarg_0);
				generator.Emit (OpCodes.Ldstr, message);
				EmitParametersAsArrayOnStack (generator, parameterInfos);
				generator.Emit (OpCodes.Call, sendMessageInvoker);

				generator.Emit (OpCodes.Ret);
			}
		}
开发者ID:Monobjc,项目名称:monobjc,代码行数:28,代码来源:WrapperGenerator.Generation.cs


示例11: SetupParameters

        public void SetupParameters(MethodBuilder methodBuilder)
        {
            if (methodToOverride.IsGenericMethod)
            {
                Type[] genericArguments = methodToOverride.GetGenericArguments();
                string[] names = genericArguments
                    .Select(t => t.Name)
                    .ToArray();
                GenericTypeParameterBuilder[] builders = methodBuilder.DefineGenericParameters(names);
                for (int i = 0; i < genericArguments.Length; ++i)
                {
                    builders[i].SetGenericParameterAttributes(genericArguments[i].GenericParameterAttributes);

                    var constraintTypes = genericArguments[i].GetGenericParameterConstraints();

                    builders[i].SetInterfaceConstraints(constraintTypes.Where(t => t.IsInterface).ToArray());
                    foreach (Type type in constraintTypes.Where(t => !t.IsInterface))
                    {
                        builders[i].SetBaseTypeConstraint(type);
                    }
                }
                for(int i = 0; i < genericArguments.Length; ++i)
                {
                    genericMethodParameters.Add(new KeyValuePair<Type, Type>(genericArguments[i], builders[i].UnderlyingSystemType));
                }
            }
        }
开发者ID:shhyder,项目名称:MapApplication,代码行数:27,代码来源:MethodOverrideParameterMapper.cs


示例12: EmitBody

 private static void EmitBody(MethodBuilder mb, Body body)
 {
     foreach (var st in body.Statements)
     {
         EmitStatement(mb, st);
     }
 }
开发者ID:BooMWax,项目名称:ifmo,代码行数:7,代码来源:Emitter.cs


示例13: TypeBuilder

 internal TypeBuilder(string szName, int genParamPos, MethodBuilder declMeth)
 {
     this.m_declMeth = declMeth;
     this.m_DeclaringType = this.m_declMeth.GetTypeBuilder();
     this.m_module = declMeth.GetModuleBuilder();
     this.InitAsGenericParam(szName, genParamPos);
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:7,代码来源:TypeBuilder.cs


示例14: RewriteInto

 public static IILRewriterContext RewriteInto(this MethodBase src, MethodBuilder dest,
     Func<IILOp, IILRewriteControl, IILRewriteControl> logic)
 {
     var rewriter = new ILRewriter(src, dest, logic);
     rewriter.DoRewrite();
     return rewriter;
 }
开发者ID:xeno-by,项目名称:truesight-lite,代码行数:7,代码来源:ILTrait.Rewrite.cs


示例15: CloneGenericMethodArguments

        protected static GenericTypeParameterBuilder[] CloneGenericMethodArguments(MethodInfo source, MethodBuilder destination)
        {
            var genericArgs = source.GetGenericArguments();

            if (genericArgs.Length == 0)
            {
                return new GenericTypeParameterBuilder[0];
            }

            var names = new string[genericArgs.Length];

            for (var i = 0; i < genericArgs.Length; i++)
            {
                names[i] = genericArgs[i].Name;
            }

            var genericTypeParameterBuilders = destination.DefineGenericParameters(names);

            for (var i = 0; i < genericTypeParameterBuilders.Length; i++)
            {
                var genericArgConstraints = genericArgs[i].GetGenericParameterConstraints();

                for (var j = 0; j < genericArgConstraints.Length; j++)
                {
                    genericTypeParameterBuilders[i].SetBaseTypeConstraint(genericArgConstraints[j]);
                }
            }

            return genericTypeParameterBuilders;
        }
开发者ID:bradleyjford,项目名称:inception,代码行数:30,代码来源:MethodGenerator.cs


示例16: Emit

        public void Emit(CompilerErrorCollection errors, MethodBuilder m)
        {
            //Set the parameters
            //ParameterBuilder[] parms = new ParameterInfo[args.Length];
            for(int i = 0; i < args.Length; i++)
                m.DefineParameter(i + 1, ParameterAttributes.None, args[i].Name);

            ILGenerator gen = m.GetILGenerator();

            //Define the IT variable
            LocalRef it = locals["IT"] as LocalRef;
            DefineLocal(gen, it);

            statements.Process(this, errors, gen);

            statements.Emit(this, gen);

            //Cast the IT variable to our return type and return it
            if (m.ReturnType != typeof(void))
            {
                gen.Emit(OpCodes.Ldloc, it.Local);
                Expression.EmitCast(gen, it.Type, m.ReturnType);
            }
            gen.Emit(OpCodes.Ret);
        }
开发者ID:unycorn,项目名称:lolcode-dot-net,代码行数:25,代码来源:Program.cs


示例17: GenCode

        public override void GenCode(TypeBuilder tb, MethodBuilder mb, ILGenerator cg)
        {
            List<Type> parametersConstructor = new List<Type>();
            List<FieldBuilder> campos = new List<FieldBuilder>();

            foreach (var item in Parameters)
            {
                parametersConstructor.Add(Compiler.SearchType(item.Type));
                campos.Add(tb.DefineField(item.Id, Compiler.SearchType(item.Type), FieldAttributes.Public));
            }

            ConstructorBuilder constructor = tb.DefineConstructor(MethodAttributes.Public, CallingConventions.HasThis, parametersConstructor.ToArray());
            Compiler.RecordConstructors.Add(new RecordsConstructors(tb.Name, constructor));
            ILGenerator ilgen = constructor.GetILGenerator();

            Type objType = Type.GetType("System.Object");
            ConstructorInfo objCtor = objType.GetConstructor(new Type[0]);//creando el contructor vacio para generar el otro
            ilgen.Emit(OpCodes.Ldarg_0);
            ilgen.Emit(OpCodes.Call, objCtor);

            int i = 1;
            foreach (var item in campos)//poniendole los valores de los campos a lsa propiedades
            {
                ilgen.Emit(OpCodes.Ldarg_0);//este objeto ilgen=contructor.getIlgenerator()
                ilgen.Emit(OpCodes.Ldarg, i);//tiene un field item
                ilgen.Emit(OpCodes.Stfld, item);//y en el se pone el valor del argumento i del contructor
                i++;
            }
            ilgen.Emit(OpCodes.Ret);

            record = tb.CreateType();
        }
开发者ID:oisbel,项目名称:TigerCompiler,代码行数:32,代码来源:TypeRecordNode.cs


示例18: GenCode

        public override void GenCode(TypeBuilder tb, MethodBuilder mb, ILGenerator cg)
        {
            LeftOperand.GenCode(tb, mb, cg);

            RigthOperand.GenCode(tb, mb, cg);
            cg.Emit(OpCodes.And);
        }
开发者ID:oisbel,项目名称:TigerCompiler,代码行数:7,代码来源:AndNode.cs


示例19: Compile

 internal void Compile(MethodBuilder m)
 {
     if (Builder == null)
     {
         int ofs = (m.IsStatic ? 0 : 1);
         Builder = m.DefineParameter(this.Index + ofs, this.Attributes, this.Name);
     }
 }
开发者ID:rreynolds-yp,项目名称:csharp-swift-consoleclient,代码行数:8,代码来源:EmittedParameter.cs


示例20: CopyGenericArguments

		public static GenericTypeParameterBuilder[] CopyGenericArguments(
			IMethodInfo methodToCopyGenericsFrom,
			MethodBuilder builder,
			Dictionary<String, GenericTypeParameterBuilder> name2GenericType)
		{
            return CopyGenericArguments(methodToCopyGenericsFrom, name2GenericType,
                                     builder.DefineGenericParameters);
		}
开发者ID:rajgit31,项目名称:MetroUnitTestsDemoApp,代码行数:8,代码来源:GenericUtil.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Emit.ModuleBuilder类代码示例发布时间:2022-05-26
下一篇:
C# Emit.LocalBuilder类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap