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


C# Emit.MethodBuilder类代码示例

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


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


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