Пример #1
0
        protected Delegate getDelegateNoCache <T>(IntPtr ptr, CallingConvention conv) where T : class
        {
            MethodInfo m    = typeof(T).GetMethod("Invoke");
            TDyn       type = wire(m, ptr, conv);

            return(type.dynamic.CreateDelegate(m.DeclaringType));
        }
Пример #2
0
        /// <summary>
        /// Magic methods. Invoking.
        /// </summary>
        /// <![CDATA[
        ///     `[result =] name<return_type>([{argument_types}])`
        /// ]]>
        /// <param name="binder"></param>
        /// <param name="args"></param>
        /// <param name="result"></param>
        /// <returns></returns>
        public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
        {
            Type[] tArgs;

            try {
                tArgs = getArgTypes(binder, args);
            }
            catch (ArgumentException ex) {
                LSender.Send(this, $"Problem with arguments. DLR for '{binder.Name}': {ex.Message}", Message.Level.Warn);
                tArgs = args.Select(a => a.GetType()).ToArray();
            }

            Type[]     tGeneric = getGenericArgTypes(binder).ToArray();
            MethodInfo mi       = getmi(binder.Name, tGeneric, tArgs);

            TDyn dyn = provider.bind(
                mi,
                provider.Svc.tryAlias(binder.Name),
                Convention
                );

            // Boxing types, for example: NullType -> null -> NullType

            object[] unboxed = unbox(args);
            result = Dynamic.DCast(dyn.returnType, dyn.dynamic.Invoke(null, unboxed));
            boxing(unboxed, args);

            return(true);
        }
Пример #3
0
        /// <typeparam name="T">The return type for new Delegate should be as T type.</typeparam>
        /// <param name="lpProcName"></param>
        /// <param name="ret">The type of return value.</param>
        /// <param name="args">The type of arguments.</param>
        /// <returns>Delegate of exported function.</returns>
        protected Method <T, object> bind <T>(LpProcName lpProcName, Type ret, params Type[] args)
        {
            MethodInfo mi  = Dynamic.GetMethodInfo((string)lpProcName, ret, args);
            TDyn       dyn = wire(mi, lpProcName, Convention);

            return(delegate(object[] _args) {
                return (T)dyn.dynamic.Invoke(null, _args);
            });
        }