Example #1
0
        static InjectableInfo CreateForConstructorParam(
            Type enclosingType, ParameterInfo paramInfo)
        {
            var injectAttr = paramInfo.Attribute<InjectAttribute>();

            return new InjectableInfo()
            {
                Optional = paramInfo.HasAttribute(typeof(InjectOptionalAttribute)),
                Identifier = (injectAttr == null ? null : injectAttr.Identifier),
                SourceName = paramInfo.Name,
                ContractType = paramInfo.ParameterType,
                EnclosingType = enclosingType,
            };
        }
Example #2
0
        /// <summary>
        /// Gets the default value associated with the given <paramref name="parameter"/>. The value is
        /// obtained from the <see href="DefaultValueAttribute"/> if present on the parameter. This method
        /// does not support C# 4.0 default parameter specifications.
        /// </summary>
        /// <returns>The default value if one could be obtained and converted into the type of the parameter,
        /// and null otherwise.</returns>
        public static object DefaultValue(this ParameterInfo parameter)
        {
            var defaultValue = parameter.Attribute <DefaultValueAttribute>();

            return(defaultValue != null?Probing.TypeConverter.Get(parameter.ParameterType, defaultValue.Value) : null);
        }
Example #3
0
        /// <summary>
        /// Determines whether the given <paramref name="parameter"/> has an associated default value as
        /// supplied by an <see href="DefaultValueAttribute"/>. This method does not read the value of
        /// the attribute. It also does not support C# 4.0 default parameter specifications.
        /// </summary>
        /// <returns>True if the attribute was detected, false otherwise.</returns>
        public static bool HasDefaultValue(this ParameterInfo parameter)
        {
            var defaultValue = parameter.Attribute <DefaultValueAttribute>();

            return(defaultValue != null);
        }