/*----------------------------------------------------------------------------------------*/
 /// <summary>
 /// Sets the value of the property associated with the injector.
 /// </summary>
 /// <param name="target">The instance on which the property should be written.</param>
 /// <param name="value">The value to store in the property.</param>
 public void Set(object target, object value)
 {
     try
     {
         _setMethod.Invoke(target, new object[] { value });
     }
     catch (TargetInvocationException ex)
     {
         // If an exception occurs inside the called member, unwrap it and re-throw.
         ExceptionThrower.RethrowPreservingStackTrace(ex.InnerException ?? ex);
     }
 }
        /*----------------------------------------------------------------------------------------*/
        #region Public Methods
        /// <summary>
        /// Gets the value of the property associated with the injector.
        /// </summary>
        /// <param name="target">The instance on which the property should be read.</param>
        /// <returns>The value stored in the property.</returns>
        public object Get(object target)
        {
            object result = null;

            try
            {
                result = _getMethod.Invoke(target, new object[0]);
            }
            catch (TargetInvocationException ex)
            {
                // If an exception occurs inside the called member, unwrap it and re-throw.
                ExceptionThrower.RethrowPreservingStackTrace(ex.InnerException ?? ex);
            }

            return(result);
        }
Пример #3
0
        /*----------------------------------------------------------------------------------------*/
        #region Public Methods
        /// <summary>
        /// Calls the method associated with the injector.
        /// </summary>
        /// <param name="target">The instance on which to call the method.</param>
        /// <param name="arguments">The arguments to pass to the method.</param>
        /// <returns>The return value of the method.</returns>
        public object Invoke(object target, params object[] arguments)
        {
            object result = null;

            try
            {
                result = Member.Invoke(target, arguments);
            }
            catch (TargetInvocationException ex)
            {
                // If an exception occurs inside the called member, unwrap it and re-throw.
                ExceptionThrower.RethrowPreservingStackTrace(ex.InnerException ?? ex);
            }

            return(result);
        }
Пример #4
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);
        }