Esempio n. 1
0
        /// <summary>
        /// Performs the call to the method defined by a previous <see cref="IMethodCall.Method"/>
        /// call, with the parameters specified by the <see cref="IMethodOperations.AddParameter"/> calls
        /// casting the return value to the specified type.
        /// </summary>
        /// <typeparam name="T">Type of the data returned by the method call</typeparam>
        /// <returns>
        /// The data returned by the method call, casted to the <typeparamref name="T">T type param</typeparamref>
        /// </returns>
        /// <remarks>
        /// The type parameter T must match the type of data returned by the method call
        /// access or an exception will be throw.
        /// </remarks>
        /// <exception cref="InvalidCastException">
        /// If the type parameter T does not match the type of data returned, thus a casting
        /// could not be performed
        /// </exception>
        public T Invoke <T>()
        {
            object retValue;

            object[] args;

            args = InnerParameterBuilder.GetParametersAsArray();

            if (InnerParameterBuilder.Count <= 0)
            {
                try
                {
                    CommonLateBindingOperations.CallOperation(
                        InstanceObject,
                        OperationName,
                        args,
                        out retValue,
                        EOperationType.Method);
                }
                catch
                {
                    throw;
                }
                finally
                {
                    ClearCall();
                }
            }
            else
            {
                ParameterModifier refParams = new ParameterModifier(args.Length);
                for (int i = 0; i < args.Length; ++i)
                {
                    refParams[i] = InnerParameterBuilder.GetReferenceParameterList()[i];
                }

                try
                {
                    CommonLateBindingOperations.CallOperation(
                        InstanceObject,
                        OperationName,
                        args,
                        out retValue,
                        refParams,
                        EOperationType.Method);
                }
                catch
                {
                    throw;
                }
                finally
                {
                    ClearCall();
                }
            }

            LastCallParameters = args;

            return(CommonLateBindingOperations.ComputeReturnType <T>(retValue));
        }