Example #1
0
        public ITargetMethod GetMethod(string methodName, int overload)
        {
            ITargetMethod targetMethod = null;

            if (_target != null)
            {
                MethodInfo[] members = _target.GetType().GetMethods(BindingFlags.Instance | BindingFlags.Public);

                for (int i = 0; i < members.Length; i++)
                {
                    MethodInfo member = members[i];

                    object[] customAttributes = member.GetCustomAttributes(typeof(TargetMethodAttribute), true);

                    if (customAttributes != null && customAttributes.Length > 0)
                    {
                        TargetMethodAttribute targetMethodAttribute = customAttributes[0] as TargetMethodAttribute;

                        if (targetMethodAttribute.Method.Equals(methodName) && targetMethodAttribute.Overload == overload)
                        {
                            targetMethod = new TargetMethod(_target, member, targetMethodAttribute.Method, targetMethodAttribute.Overload);
                        }
                    }
                }
            }
            return(targetMethod);
        }
Example #2
0
        private void PopulateCache()
        {
            if (_targetObject != null)
            {
                ITargetMethod[] methods = _targetObject.GetAllMethods();

                for (int i = 0; i < methods.Length; i++)
                {
                    ITargetMethod method = methods[i];
                    string        key    = GetCacheKey(method.GetMethodName(), method.GetOverlaod());
                    if (!_cache.ContainsKey(key))
                    {
                        _cache.Add(key, method);
                    }
                }
            }
        }
Example #3
0
        public object InvokeMethodOnTarget(string methodName, int overload, object[] arguments)
        {
            ITargetMethod targetMethod = _rpcCache.GetTargetMethod(methodName, overload);

            if (targetMethod == null)
            {
                throw new System.Reflection.TargetInvocationException("Target method not found (Method: " + methodName + " , overload : " + overload + ")", null);
            }

            if (targetMethod.GetNumberOfArguments() != arguments.Length)
            {
                throw new System.Reflection.TargetParameterCountException();
            }

            object returnVal = targetMethod.Invoke(arguments);

            return(returnVal);
        }
Example #4
0
        private void PopulateCache()
        {
            if (_targetObject != null)
            {
                ITargetMethod[] methods = _targetObject.GetAllMethods();

                for (int i = 0; i < methods.Length; i++)
                {
                    ITargetMethod method = methods[i];
                    string        key    = GetCacheKey(method.GetMethodName(), method.GetOverlaod());
                    if (!_cache.ContainsKey(key))
                    {
                        _cache.Add(key, method);
                    }
                    else
                    {
                        throw new Exception("Duplicate method exists in the target object. (Method :" + method.GetMethodName() + " , overlaod :" + method.GetOverlaod() + ")");
                    }
                }
            }
        }