Converts a data type to another data type, smarter than the standard Convert class, including collections and their items as well as object properties (duck typing). With special support for DateTime conversions.
DeepConvert should be able to convert between byte collections and strings.
This requires the specification of an Encoding. Since the ChangeType method would get too many parameters, all of them will be moved to a separate DeepConvertSettings (or similar) class that contains a property for each parameter.
The default encoding is UTF-8, like everywhere else in .NET.
Each supported date/time format has a characteristic value range for "current" dates. If a date is known or expected to be current, the date format may be detected from the range of the provided numeric value.
Define what "current" means. Examples:
Now ± 10 years, if that's practical.
Interpret the number as all known formats and choose the format closest to now.
DeepConvert should be able to convert data between the following types:
Dictionary<string, object> – class { … } (with same dictionary keys and properties/fields)
class { … } – class { … } (with same property/field names)
Property/field names should be matched case-insensitively, unless that would be ambiguous. If a property/field is itself of a composite type, the conversion recurses into that property/field.
Only public properties/fields are regarded, but the type itself should not necessarily be public.
Reflection data about the involved types should be cached for better performance. This might be a with compiled expressions or Reflection.Emit.
Like the Convert class, DeepConvert should have specialised ToX methods like ToInt32, ToString, ToDictionary<TKey, TValue> etc. These methods are shortcuts to the ChangeType method to make the API a bit friendlier. Each of these methods accepts the value to convert, and optionally also a Settings object with further options (see #5).
Verify which ISO 8601 formats and variants .NET DateTime already parses. The separators ("-", ":") are optional. Additional formats include the week, day of week, and day of year notations.
Add support for TimeSpan from a period notation or a range notation of two date/time values.
If the conversion fails, an exception is thrown. As an alternative, new Try… methods should return a bool value that indicates the success of the conversion.
If the converter is running out of options, it could look for a public static op_Implicit or op_Explicit method on the source type that returns the destination type and accepts a single parameter of the source type, then call it.