예제 #1
0
        /// <summary>
        /// Adds the static method reflection taken from the specified
        /// <paramref name="type"/> by the <paramref name="methodName"/>
        /// and arguments count to the <see cref="FunctionCollection{T}"/>
        /// with the function name, taken from real method name.</summary>
        /// <param name="type">Type object.</param>
        /// <param name="methodName">Type's method name to be imported.</param>
        /// <param name="parametersCount">Method parameters count.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="type"/> is null.<br/>-or-<br/>
        /// <paramref name="methodName"/>is null.</exception>
        /// <exception cref="ArgumentOutOfRangeException">
        /// <paramref name="parametersCount"/> is less than 0.</exception>
        /// <exception cref="ArgumentException">
        /// Method with <paramref name="methodName"/> is not founded.
        /// <br/>-or-<br/>Founded method is not valid to be added
        /// to the <see cref="FunctionCollection{T}"/>.
        /// <br/>-or-<br/><see cref="FunctionInfo{T}"/>
        /// with the same name and the same arguments count already
        /// exist in the collection (overload impossible).</exception>
        public void Import(
            string methodName, Type type, int parametersCount)
        {
            if (parametersCount < 0)
            {
                throw new ArgumentOutOfRangeException("parametersCount");
            }

            var method = FunctionFactory <T> .TryResolve(
                type, methodName, parametersCount);

            Validator.CheckVisible(method);

            AddFunc(FunctionFactory <T>
                    .FromReflection(method, null, true));
        }
예제 #2
0
        /// <summary>
        /// Adds the instance method reflection to the
        /// <see cref="FunctionCollection{T}"/> with the
        /// function name, taken from real method name.</summary>
        /// <param name="method">
        /// <see cref="MethodInfo"/> instance to add.</param>
        /// <param name="target">Instance method target object.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="method"/> is null.<br/>-or-<br/>
        /// <paramref name="target"/> is null.</exception>
        /// <exception cref="ArgumentException">
        /// <paramref name="method"/> is not valid method to
        /// be added to the <see cref="FunctionCollection{T}"/>.
        /// <br/>-or-<br/><see cref="FunctionInfo{T}"/> with the
        /// same name and same arguments count already exist
        /// in the collection (overload impossible).</exception>
        public void AddInstance(MethodInfo method, object target)
        {
            if (method == null)
            {
                throw new ArgumentNullException("method");
            }
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }

            Validator.CheckVisible(method);

            AddFunc(FunctionFactory <T>
                    .FromReflection(method, target, true));
        }
예제 #3
0
        void InternalImport(Type type, BindingFlags flags)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            foreach (var method in type.GetMethods(flags))
            {
                var func = FunctionFactory <T>
                           .FromReflection(method, null, false);

                if (func != null)
                {
                    AddFunc(func);
                }
            }
        }