Exemplo n.º 1
0
        /// <summary>
        /// Invokes proxy methods which return a value.
        /// </summary>
        /// <typeparam name="T">The return type of the method being invoked.</typeparam>
        /// <param name="args">The arguments to pass to the method.</param>
        /// <returns>The return value of the default proxy method.</returns>
        /// <remarks>This method will invoke methods on all of the proxy objects, but will return
        /// the result of the invocation on the default object.
        /// </remarks>
        protected T ProxyInvoke <T>(params object[] args)
        {
            if (objects.Count == 0)
            {
                return(default(T));
            }

            StackTrace trace  = new StackTrace();
            StackFrame frame  = trace.GetFrame(1);
            MethodInfo method = frame.GetMethod() as MethodInfo;
            ProxyAttributeCollection attributes = GetAttributes(method);

            bool first  = true;
            T    result = default(T);

            foreach (object invoke in objects)
            {
                ProxyTypeBindingAttribute binding  = attributes.GetTypeBinding(invoke);
                MemberInfoAccessor        accessor = binding.GetTargetAccessor(typeof(T), args);
                if (first)
                {
                    result = (T)accessor.Get(invoke, args);
                    first  = false;
                }
                else
                {
                    accessor.Get(invoke, args);
                }
            }

            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Performs the get operation on the first object in the list of proxy objects (the default object).
        /// </summary>
        /// <typeparam name="T">The type to cast the return value as.</typeparam>
        /// <param name="args">The indices to pass to the get method.</param>
        /// <returns>The result of executing a get operation on the default proxy object, or the default value of T
        /// if there are no proxy objects.
        /// </returns>
        public T ProxyGet <T>(params object[] args)
        {
            if (objects.Count == 0)
            {
                return(default(T));
            }

            StackTrace trace  = new StackTrace();
            StackFrame frame  = trace.GetFrame(1);
            MethodInfo method = frame.GetMethod() as MethodInfo;
            ProxyAttributeCollection  attributes = GetAttributes(method);
            ProxyTypeBindingAttribute binding    = attributes.GetTypeBinding(objects[0]);
            MemberInfoAccessor        accessor   = binding.GetTargetAccessor(typeof(T), args);

            return((T)accessor.Get(objects[0], args));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Invokes proxy methods which do not return a value.
        /// </summary>
        /// <param name="args">The arguments to pass to the method.</param>
        protected void ProxyInvoke(params object[] args)
        {
            if (objects.Count == 0)
            {
                return;
            }

            StackTrace trace  = new StackTrace();
            StackFrame frame  = trace.GetFrame(1);
            MethodInfo method = frame.GetMethod() as MethodInfo;
            ProxyAttributeCollection attributes = GetAttributes(method);

            foreach (object invoke in objects)
            {
                ProxyTypeBindingAttribute binding  = attributes.GetTypeBinding(invoke);
                MemberInfoAccessor        accessor = binding.GetTargetAccessor(typeof(void), args);
                accessor.Get(invoke, args);
            }
        }