/// <summary> /// Creates a function for the given conversion where neither input and output are an <see cref="Enum"/>. /// </summary> /// <param name="input">The <see cref="Type"/> to convert from.</param> /// <param name="output">The <see cref="Type"/> to convert to.</param> /// <returns>The function that converts an object of the given <see cref="Type"/> to the specified <see cref="Type"/>.</returns> protected override Func <object, object> Lookup(Type input, Type output) { if (output == typeof(string)) { return(Conversions.ObjectToString); } if (output.IsAssignableFrom(input)) { return(Conversions.None); } Tuple <Type, Type> inout = Tuple.Create(input, output); if (!LookupCache.TryGetValue(inout, out Func <object, object> converter)) { converter = (input == typeof(string) ? Conversions.TryParse(output) : null) ?? Conversions.ImplicitCast(input, output) ?? Conversions.ExplicitCast(input, output) ?? Conversions.TypeConverter(input, output); if (converter != null) { LookupCache[inout] = converter; } else { converter = InvalidConversion; } } return(converter); }
/// <summary> /// Creates a function for the given conversion which includes at least one <see cref="Enum"/>. /// </summary> /// <param name="input">The <see cref="Type"/> to convert from.</param> /// <param name="inputTypeCode">The <see cref="TypeCode"/> of <paramref name="input"/>.</param> /// <param name="output">The <see cref="Type"/> to convert to.</param> /// <param name="outputTypeCode">The <see cref="TypeCode"/> of <paramref name="output"/>.</param> protected override Func <object, object> LookupEnum(Type input, TypeCode inputTypeCode, Type output, TypeCode outputTypeCode) { if (outputTypeCode == TypeCode.String) { return(Conversions.ObjectToString); } if (inputTypeCode == TypeCode.String) { Tuple <Type, Type> inout = Tuple.Create(input, output); if (!LookupCache.TryGetValue(inout, out Func <object, object> converter)) { converter = Conversions.TryParseEnum(output); LookupCache[inout] = converter; } return(converter); } return(this[inputTypeCode, outputTypeCode]); }