Ejemplo n.º 1
0
        Emit <DelegateType> InnerLoadFunctionPointer(MethodInfo method, Type[] parameterTypes)
        {
            var type =
                TypeOnStack.GetKnownFunctionPointer(
                    method.CallingConvention,
                    HasFlag(method.CallingConvention, CallingConventions.HasThis) ? method.DeclaringType : null,
                    method.ReturnType,
                    parameterTypes
                    );

            UpdateState(OpCodes.Ldftn, method, parameterTypes, Wrap(new[] { new StackTransition(new TypeOnStack[0], new[] { type }) }, "LoadFunctionPointer"));

            return(this);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Pops an object reference off the stack, and pushes a pointer to the given method's implementation on that object.
        ///
        /// For static or non-virtual functions, use LoadFunctionPointer
        /// </summary>
        public Emit <DelegateType> LoadVirtualFunctionPointer(MethodInfo method)
        {
            if (method == null)
            {
                throw new ArgumentNullException("method");
            }

            if (method.IsStatic)
            {
                throw new ArgumentException("Only non-static methods can be passed to LoadVirtualFunctionPointer, found " + method);
            }

            var thisType =
                HasFlag(method.CallingConvention, CallingConventions.HasThis) ?
                method.DeclaringType :
                null;

            var parameters = method.GetParameters();
            var paramList  = LinqAlternative.Select(parameters, p => p.ParameterType).ToList();

            var declaring = method.DeclaringType;

            if (TypeHelpers.IsValueType(declaring))
            {
                declaring = declaring.MakePointerType();
            }

            paramList.Insert(0, declaring);

            var type =
                TypeOnStack.GetKnownFunctionPointer(
                    method.CallingConvention,
                    thisType,
                    method.ReturnType,
                    paramList.ToArray()
                    );

            var transitions =
                new[]
            {
                new StackTransition(new [] { declaring }, new [] { typeof(NativeIntType) })
            };

            UpdateState(OpCodes.Ldvirtftn, method, LinqAlternative.Select(parameters, p => p.ParameterType).AsEnumerable(), Wrap(transitions, "LoadVirtualFunctionPointer"));

            return(this);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Pushes a pointer to the given function onto the stack, as a native int.
        ///
        /// To resolve a method at runtime using an object, use LoadVirtualFunctionPointer instead.
        /// </summary>
        public Emit <DelegateType> LoadFunctionPointer(MethodInfo method)
        {
            if (method == null)
            {
                throw new ArgumentNullException("method");
            }

            var parameters = method.GetParameters();

            var paramList = ((LinqArray <ParameterInfo>)parameters).Select(p => p.ParameterType).ToList();

            var type =
                TypeOnStack.GetKnownFunctionPointer(
                    method.CallingConvention,
                    HasFlag(method.CallingConvention, CallingConventions.HasThis) ? method.DeclaringType : null,
                    method.ReturnType,
                    paramList.ToArray()
                    );

            UpdateState(OpCodes.Ldftn, method, paramList.AsEnumerable(), Wrap(new[] { new StackTransition(new TypeOnStack[0], new[] { type }) }, "LoadFunctionPointer"));

            return(this);
        }
        Emit <DelegateType> InnerLoadVirtualFunctionPointer(MethodInfo method, Type[] parameterTypes)
        {
            var thisType =
                HasFlag(method.CallingConvention, CallingConventions.HasThis) ?
                method.DeclaringType :
                null;

            var paramList = new List <Type>(parameterTypes);

            var declaring = method.DeclaringType;

            if (TypeHelpers.IsValueType(declaring))
            {
                declaring = declaring.MakePointerType();
            }

            paramList.Insert(0, declaring);

            var type =
                TypeOnStack.GetKnownFunctionPointer(
                    method.CallingConvention,
                    thisType,
                    method.ReturnType,
                    paramList.ToArray()
                    );

            var transitions =
                new[]
            {
                new StackTransition(new [] { declaring }, new [] { typeof(NativeIntType) })
            };

            UpdateState(OpCodes.Ldvirtftn, method, parameterTypes, Wrap(transitions, "LoadVirtualFunctionPointer"));

            return(this);
        }