/// <summary> /// Converts the string representation of the <paramref name="input"/> /// object to a <typeparamref name="TEnum"/> value. /// </summary> /// <param name="input"> /// The object to convert. /// </param> /// <returns> /// Result of the conversion. /// </returns> /// <exception cref="InvalidDataException"> /// The <paramref name="input"/> does not represent a /// <typeparamref name="TEnum"/> /// value. /// </exception> public override TEnum Convert(object input) { var x = input as TEnum?; if (x != null) { return(x.Value); } TEnum value; if (InputConversionTable.TryGetValue(input.ToString(), out value)) { return(value); } throw NewInvalidDataException(input); }
/// <summary> /// Converts the string representation of the <see cref="input"/> /// object to a <see cref="TEnum"/> value. /// </summary> /// <param name="input"> /// The object to convert. /// </param> /// <returns> /// Result of the conversion. /// </returns> /// <exception cref="InvalidDataException"> /// The <see cref="input"/> does not represent a <see cref="TEnum"/> /// value. /// </exception> public override TEnum Convert(object input) { var x = input as TEnum?; if (x != null) { return(x.Value); } TEnum value; if (InputConversionTable.TryGetValue(input.ToString(), out value)) { return(value); } throw new InvalidDataException(string.Format("Expected {0}: {1}", TypeName, input)); // TODO: improved diagnostices }