コード例 #1
0
        public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
        {
            // Get type args of the call
            Type[] typeArgs = ExposedObjectHelper.GetTypeArgs(binder);
            if (typeArgs != null && typeArgs.Length == 0)
            {
                typeArgs = null;
            }

            //
            // Try to call a non-generic instance method
            //
            if (typeArgs == null &&
                m_instanceMethods.ContainsKey(binder.Name) &&
                m_instanceMethods[binder.Name].ContainsKey(args.Length) &&
                ExposedObjectHelper.InvokeBestMethod(args, m_object, m_instanceMethods[binder.Name][args.Length], out result))
            {
                return(true);
            }

            //
            // Try to call a generic instance method
            //
            if (m_genInstanceMethods.ContainsKey(binder.Name) &&
                m_genInstanceMethods[binder.Name].ContainsKey(args.Length))
            {
                List <MethodInfo> methods = new List <MethodInfo>();

                foreach (var method in m_genInstanceMethods[binder.Name][args.Length])
                {
                    if (method.GetGenericArguments().Length == typeArgs.Length)
                    {
                        methods.Add(method.MakeGenericMethod(typeArgs));
                    }
                }

                if (ExposedObjectHelper.InvokeBestMethod(args, m_object, methods, out result))
                {
                    return(true);
                }
            }

            result = null;
            return(false);
        }
コード例 #2
0
        public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
        {
            // Get type args of the call
            Type[] typeArgs = ExposedObjectHelper.GetTypeArgs(binder);
            if (typeArgs != null && typeArgs.Length == 0)
            {
                typeArgs = null;
            }

            //
            // Try to call a non-generic instance method
            //
            if (typeArgs == null &&
                m_staticMethods.ContainsKey(binder.Name) &&
                m_staticMethods[binder.Name].ContainsKey(args.Length) &&
                ExposedObjectHelper.InvokeBestMethod(args, null, m_staticMethods[binder.Name][args.Length], out result))
            {
                return(true);
            }

            result = null;
            return(false);
        }