コード例 #1
0
 private static void GuardPropertyValueIsCompatible(PropertyInfo property, InjectionParameterValue value)
 {
     if (!value.MatchesType(property.PropertyType))
     {
         throw new InvalidOperationException(
                   ExceptionMessage(Constants.PropertyTypeMismatch,
                                    property.Name,
                                    property.DeclaringType,
                                    property.PropertyType,
                                    value.ParameterTypeName));
     }
 }
コード例 #2
0
        /// <summary>
        /// Convert an arbitrary value to an InjectionParameterValue object. The rules are:
        /// If it's already an InjectionParameterValue, return it. If it's a Type, return a
        /// ResolvedParameter object for that type. Otherwise return an InjectionParameter
        /// object for that value.
        /// </summary>
        /// <param name="value">The value to convert.</param>
        /// <returns>The resulting <see cref="InjectionParameterValue"/>.</returns>
        public static InjectionParameterValue ToParameter(object value)
        {
            InjectionParameterValue parameterValue = value as InjectionParameterValue;

            if (parameterValue != null)
            {
                return(parameterValue);
            }

            Type typeValue = value as Type;

            if (typeValue != null)
            {
                return(new ResolvedParameter(typeValue));
            }

            return(new InjectionParameter(value));
        }
コード例 #3
0
 /// <summary>
 /// Configure the container to inject the given property name,
 /// using the value supplied. This value is converted to an
 /// <see cref="InjectionParameterValue"/> object using the
 /// rules defined by the <see cref="InjectionParameterValue.ToParameters"/>
 /// method.
 /// </summary>
 /// <param name="propertyName">Name of property to inject.</param>
 /// <param name="propertyValue">Value for property.</param>
 public InjectionProperty(string propertyName, object propertyValue)
 {
     _propertyName   = propertyName;
     _parameterValue = InjectionParameterValue.ToParameter(propertyValue);
 }
コード例 #4
0
 /// <summary>
 /// Create a new <see cref="InjectionMethod"/> instance which will configure
 /// the container to call the given methods with the given parameters.
 /// </summary>
 /// <param name="methodName">Name of the method to call.</param>
 /// <param name="methodParameters">Parameter values for the method.</param>
 public InjectionMethod(string methodName, params object[] methodParameters)
 {
     _methodName       = methodName;
     _methodParameters = InjectionParameterValue.ToParameters(methodParameters).ToList();
 }
コード例 #5
0
 /// <summary>
 /// Create a new instance of <see cref="InjectionConstructor"/> that looks
 /// for a constructor with the given set of parameters.
 /// </summary>
 /// <param name="parameterValues">The values for the parameters, that will
 /// be converted to <see cref="InjectionParameterValue"/> objects.</param>
 public InjectionConstructor(params object[] parameterValues)
 {
     _parameterValues = InjectionParameterValue.ToParameters(parameterValues).ToList();
 }