/// <summary> /// Converts the query parameter value to an object. /// </summary> /// <param name="processingContext">The <see cref="processingContext"/> which holds information about the current value.</param> /// <returns>The newly created object.</returns> /// <exception cref="ArgumentNullException">The value of 'processingContext' cannot be null. </exception> public Object Resolve(ParserProcessingContext processingContext) { if (processingContext == null) { throw new ArgumentNullException(nameof(processingContext)); } return(Convert.ChangeType(processingContext.SourceValue, processingContext.DestinationType)); }
/// <summary> /// Converts the query parameter value to an object. /// </summary> /// <param name="processingContext">The <see cref="processingContext"/> which holds information about the current value.</param> /// <returns>The newly created object.</returns> /// <exception cref="ArgumentNullException">The value of '<paramref name="processingContext"/>' cannot be null. </exception> public Object Resolve(ParserProcessingContext processingContext) { if (processingContext == null) { throw new ArgumentNullException(nameof(processingContext)); } return(CultureInfo.GetCultures(CultureTypes.AllCultures).First(cultureInfo => cultureInfo.TwoLetterISOLanguageName == processingContext.SourceValue)); }
/// <summary> /// Converts the query parameter value to an object. /// </summary> /// <param name="processingContext">The <see cref="processingContext"/> which holds information about the current value.</param> /// <returns>The newly created object.</returns> /// <exception cref="ArgumentNullException">The value of 'processingContext' cannot be null. </exception> public Object Resolve(ParserProcessingContext processingContext) { if (processingContext == null) { throw new ArgumentNullException(nameof(processingContext)); } return(processingContext.SourceValue == "1"); }
/// <summary> /// Converts the query parameter value to an object. /// Always returns the default value of the <see cref="Type"/>. /// </summary> /// <param name="processingContext">The <see cref="processingContext"/> which holds information about the current value.</param> /// <returns>The newly created object.</returns> /// <exception cref="ArgumentNullException">The value of '<paramref name="processingContext"/>' cannot be null. </exception> public Object Resolve(ParserProcessingContext processingContext) { if (processingContext == null) { throw new ArgumentNullException(nameof(processingContext)); } return(processingContext.DestinationType.GetDefault()); }
/// <summary> /// Converts the query parameter value to an object. /// </summary> /// <param name="processingContext">The <see cref="processingContext"/> which holds information about the current value.</param> /// <returns>The newly created object.</returns> /// <exception cref="ArgumentNullException">The value of '<paramref name="processingContext"/>' cannot be null. </exception> public Object Resolve(ParserProcessingContext processingContext) { if (processingContext == null) { throw new ArgumentNullException(nameof(processingContext)); } return(this.typeConverter.ConvertFromString(processingContext.SourceValue)); }
/// <summary> /// Converts the query parameter value to an object. /// </summary> /// <param name="processingContext">The <see cref="processingContext"/> which holds information about the current value.</param> /// <returns>The newly created object.</returns> /// <exception cref="ArgumentNullException">The value of 'processingContext' cannot be null. </exception> /// <exception cref="InvalidOperationException">The <see cref="EnumValueNameAttribute"/>-Attribute was not found on the supplied Enum value. Or there is no <see cref="EnumValueNameAttribute"/> with the supplied value name.</exception> /// <exception cref="EnumValueNameAttributeNotFoundException">The EnumValueNameAttribute-attribute was not found on the supplied member '<paramref name="valueName"/>' of enum '<paramref name="enumType"/>'.</exception> /// <exception cref="MissingMemberException">There is no enum-member whith the specified name.</exception> public Object Resolve(ParserProcessingContext processingContext) { if (processingContext == null) { throw new ArgumentNullException(nameof(processingContext)); } return(processingContext.SourceValue.GetEnumMemberByValueName(processingContext.DestinationType)); }
/// <summary> /// Converts the query parameter value to an object. /// </summary> /// <param name="processingContext">The <see cref="processingContext"/> which holds information about the current value.</param> /// <returns>The newly created object.</returns> /// <exception cref="ArgumentNullException">The value of 'processingContext' cannot be null. </exception> public Object Resolve(ParserProcessingContext processingContext) { if (processingContext == null) { throw new ArgumentNullException(nameof(processingContext)); } var seconds = Int64.Parse(processingContext.SourceValue); return(seconds.FromUnixTimestamp()); }
/// <summary> /// Converts the query parameter value to an object. /// </summary> /// <param name="processingContext">The <see cref="processingContext"/> which holds information about the current value.</param> /// <returns>The newly created object.</returns> /// <exception cref="ArgumentNullException">The value of '<paramref name="processingContext"/>' cannot be null. </exception> public Object Resolve(ParserProcessingContext processingContext) { if (processingContext == null) { throw new ArgumentNullException(nameof(processingContext)); } var lazyType = typeof(Lazy <>); var lazyGenericType = processingContext.DestinationType.GetSingleGenericParameter(); var genericLazy = lazyType.MakeGenericType(lazyGenericType); var resolvedValue = this.innerValueProcessor.Resolve(processingContext.CreateProcessingContext(processingContext.SourceValue, lazyGenericType)); var lazy = Activator.CreateInstance(genericLazy, this.CreateActivatorFunction(resolvedValue, lazyGenericType)); return(lazy); }
/// <summary> /// Converts the query parameter value to an object. /// </summary> /// <param name="processingContext">The <see cref="processingContext"/> which holds information about the current value.</param> /// <returns>The newly created object.</returns> /// <exception cref="ArgumentNullException">The value of 'processingContext' cannot be null. </exception> /// <exception cref="ValueProcessorCannotHandleTypeException">The itemValueProcessor can not handle the specified <see cref="Type"/> if elements.</exception> public virtual Object Resolve(ParserProcessingContext processingContext) { if (processingContext == null) { throw new ArgumentNullException(nameof(processingContext)); } var splittedValues = Regex.Split(processingContext.SourceValue, processingContext.Configuration.QueryParameterSplitValuesRegexPattern, RegexOptions.Singleline); if (!processingContext.DestinationType.IsGenericIEnumerable()) { return(splittedValues.AsEnumerable()); } return(this.MakeGenericEnumerable(splittedValues, processingContext.DestinationType, processingContext)); }
/// <summary> /// Creates a generic list, converts each item to the destination value and fills the list. /// </summary> /// <param name="values">The values to convert and add.</param> /// <param name="enumerableType">The <see cref="Type"/> of the list.</param> /// <param name="processingContext">The supplied <see cref="ParserProcessingContext"/> from the caller.</param> /// <exception cref="ValueProcessorCannotHandleTypeException">The itemValueProcessor can not handle the specified <see cref="Type"/> if elements.</exception> /// <returns>A newly created list filled with the converted values.</returns> /// <exception cref="ArgumentNullException">The value of '<paramref name="values"/>' and <paramref name="enumerableType"/> cannot be null. </exception> private IEnumerable MakeGenericEnumerable([NotNull] IEnumerable <String> values, [NotNull] Type enumerableType, [NotNull] ParserProcessingContext processingContext) { if (values == null) { throw new ArgumentNullException(nameof(values)); } if (enumerableType == null) { throw new ArgumentNullException(nameof(enumerableType)); } var genericType = enumerableType.GetSingleGenericParameter(); var checkType = genericType; if (genericType.IsNullable()) { checkType = genericType.GetSingleGenericParameter(); } if (!this.itemValueProcessor.CanHandle(checkType)) { throw new ValueProcessorCannotHandleTypeException(this.itemValueProcessor, genericType); } var resultTypeDefinition = typeof(Collection <>).MakeGenericType(genericType); var result = Activator.CreateInstance(resultTypeDefinition); var addMethod = resultTypeDefinition.GetMethod("Add", new[] { genericType }); foreach (var value in values) { var innerProcessingContext = processingContext.CreateProcessingContext(value, genericType); var resolvedValue = this.itemValueProcessor.Resolve(innerProcessingContext); addMethod.Invoke(result, new[] { resolvedValue }); } return(result as IEnumerable); }