Esempio n. 1
0
        /*----------------------------------------------------------------------------------------*/
        #region Public Methods
        /// <summary>
        /// Creates a new instance of a type by calling the injector's constructor.
        /// </summary>
        /// <param name="arguments">The arguments to pass to the constructor.</param>
        /// <returns>A new instance of the type associated with the injector.</returns>
        public object Invoke(params object[] arguments)
        {
            object instance = null;

            try
            {
                // Call the injection constructor.
                instance = Member.Invoke(arguments);
            }
            catch (TargetInvocationException ex)
            {
                // If an exception occurs inside the called member, unwrap it and re-throw.
                ExceptionThrower.RethrowPreservingStackTrace(ex.InnerException ?? ex);
            }
            catch (Exception ex)
            {
                throw new ActivationException(ExceptionFormatter.CouldNotCreateInstanceOfType(Member.ReflectedType, ex), ex);
            }

            return(instance);
        }