예제 #1
0
        private void invokeInstanceBuilder()
        {
            ILVariable      obj           = this._instance;
            ILMethodBuilder methodBuilder = this._methodBuilder;

            Type[]   genericArgs  = this._genericArgs;
            ILData[] invokeParams = this._parameters;

            MethodInfo method = methodBuilder.MethodBuilder;

            if (genericArgs == null || genericArgs.Length == 0)
            {
                if (obj.ILType.IsValueType)
                {
                    ((IILPusher)obj).PushAddress();
                }
                else
                {
                    if (obj.ILType.IsGenericParameter)
                    {
                        ((IILPusher)obj).PushAddress();
                        obj.Coding.Generator.Emit(OpCodes.Constrained, obj.ILType);
                    }
                    else
                    {
                        ((IILPusher)obj).Push();
                    }
                }

                if (invokeParams != null)
                {
                    Type   typeOfObject   = typeof(object);
                    Type[] parameterTypes = methodBuilder.GetParameterTypes();
                    for (int i = 0; i < invokeParams.Length; i++)
                    {
                        ILData invokeParam   = invokeParams[i];
                        Type   parameterType = parameterTypes[i];
                        if (parameterType.IsByRef)
                        {
                            ((IILPusher)invokeParam).PushAddress();
                        }
                        else
                        {
                            if (parameterType == typeOfObject)
                            {
                                ((IILPusher)invokeParam).Push();
                                obj.Generator.Emit(OpCodes.Box, invokeParam.ILType);
                            }
                            else
                            {
                                ((IILPusher)invokeParam).Push();
                            }
                        }
                    }
                }

                //if (method.IsVirtual)
                //    obj.Generator.Emit(OpCodes.Callvirt, method);
                //else
                obj.Generator.Emit(OpCodes.Call, method);
            }
            else
            {
                if (obj.ILType.IsValueType)
                {
                    ((IILPusher)obj).PushAddress();
                }
                else
                {
                    if (obj.ILType.IsGenericParameter)
                    {
                        ((IILPusher)obj).PushAddress();
                        obj.Coding.Generator.Emit(OpCodes.Constrained, obj.ILType);
                    }
                    else
                    {
                        ((IILPusher)obj).Push();
                    }
                }

                if (invokeParams != null)
                {
                    Type   typeOfObject   = typeof(object);
                    Type[] parameterTypes = methodBuilder.GetParameterTypes();
                    for (int i = 0; i < invokeParams.Length; i++)
                    {
                        ILData invokeParam = invokeParams[i];
                        if (parameterTypes[i] == typeOfObject)
                        {
                            ((IILPusher)invokeParam).Push();
                            obj.Generator.Emit(OpCodes.Box, invokeParam.ILType);
                        }
                        else
                        {
                            ((IILPusher)invokeParam).Push();
                        }
                    }
                }
                method = method.MakeGenericMethod(genericArgs);
                //if (method.IsVirtual)
                //    obj.Generator.Emit(OpCodes.Callvirt, method);
                //else
                obj.Generator.Emit(OpCodes.Call, method);
            }
        }
예제 #2
0
        private void invokeStaticBuilder()
        {
            ILMethodBuilder staticMethodBuilder = this._methodBuilder;

            Type[]   genericArgs  = this._genericArgs;
            ILData[] invokeParams = this._parameters;

            if (genericArgs == null || genericArgs.Length == 0)
            {
                if (invokeParams != null)
                {
                    Type   typeOfObject   = typeof(object);
                    Type[] parameterTypes = staticMethodBuilder.GetParameterTypes();
                    for (int i = 0; i < invokeParams.Length; i++)
                    {
                        ILData invokeParam   = invokeParams[i];
                        Type   parameterType = parameterTypes[i];
                        if (parameterType.IsByRef)
                        {
                            ((IILPusher)invokeParam).PushAddress();
                        }
                        else
                        {
                            if (parameterTypes[i] == typeOfObject)
                            {
                                ((IILPusher)invokeParam).Push();
                                this.Generator.Emit(OpCodes.Box, invokeParam.ILType);
                            }
                            else
                            {
                                ((IILPusher)invokeParam).Push();
                            }
                        }
                    }
                }
                this.Generator.Emit(OpCodes.Call, staticMethodBuilder.MethodBuilder);
            }
            else
            {
                if (invokeParams != null)
                {
                    Type   typeOfObject   = typeof(object);
                    Type[] parameterTypes = staticMethodBuilder.GetParameterTypes();
                    for (int i = 0; i < invokeParams.Length; i++)
                    {
                        ILData invokeParam   = invokeParams[i];
                        Type   parameterType = parameterTypes[i];
                        if (parameterType.IsByRef)
                        {
                            ((IILPusher)invokeParam).PushAddress();
                        }
                        else
                        {
                            if (parameterTypes[i] == typeOfObject)
                            {
                                ((IILPusher)invokeParam).Push();
                                this.Generator.Emit(OpCodes.Box, invokeParam.ILType);
                            }
                            else
                            {
                                ((IILPusher)invokeParam).Push();
                            }
                        }
                    }
                }
                MethodInfo method = staticMethodBuilder.MethodBuilder.MakeGenericMethod(genericArgs);
                this.Generator.Emit(OpCodes.Call, method);
            }
        }