Beispiel #1
0
        /// <summary>
        /// Uses reflection to dynamically invoke a method,
        /// throwing an exception if it is not
        /// implemented on the target object.
        /// </summary>
        /// <param name="obj">
        /// Object containing method.
        /// </param>
        /// <param name="info">
        /// MethodInfo for the method.
        /// </param>
        /// <param name="parameters">
        /// Parameters to pass to method.
        /// </param>
        public static object CallMethod(object obj, MethodInfo info, params object[] parameters)
        {
            DynamicMethodHandle cachedMethod = MethodCaller.GetCachedMethod(obj, info, parameters);

            if (cachedMethod == null || cachedMethod.DynamicMethod == null)
            {
                throw new NotImplementedException(info.Name + " not implemented.");
            }
            return(MethodCaller.CallMethod(obj, cachedMethod, parameters));
        }
Beispiel #2
0
        /// <summary>
        /// Uses reflection to dynamically invoke a method
        /// if that method is implemented on the target object.
        /// </summary>
        /// <param name="obj">
        /// Object containing method.
        /// </param>
        /// <param name="method">
        /// Name of the method.
        /// </param>
        /// <param name="parameters">
        /// Parameters to pass to method.
        /// </param>
        public static object CallMethodIfImplemented(object obj, string method, params object[] parameters)
        {
            DynamicMethodHandle cachedMethod = MethodCaller.GetCachedMethod(obj, method, parameters);

            if (cachedMethod == null || cachedMethod.DynamicMethod == null)
            {
                return(null);
            }
            return(MethodCaller.CallMethod(obj, cachedMethod, parameters));
        }