Repository navigation
v2.0.0
Conversions now reach enums and value types such as Guid, TimeSpan and DateOnly, can read text in a culture the caller chooses, and cost no exception for text that does not convert. IEnumerableToDataTable converts any list without throwing, and ToTitleCase gives the same result on every machine. Several of the fixes change what callers see, hence the major version.
Breaking changes
- The package targets net8.0, net9.0 and net10.0. net7.0, which is out of support, is dropped.
- An enum converts from its name, in any case, or from a whole number, as text or as a value of an integer type, and like any enum it takes a number it has no name for. Text converts to
Guid,TimeSpan,DateTimeOffset,DateOnly,TimeOnly,Int128,BigIntegerand any other value type with a public staticTryParse(string, IFormatProvider, out T). All of these used to give the default,nullorfalsefor every value, inToNonNullableType,ToNullableType,IsParseableandToNonNullableCollectionTypealike. IEnumerableToDataTablemakes columns only of public instance properties with a public getter. Static properties, and properties whose getter is private, used to be columns too. Anullelement gives a row ofDBNull.Value, and anulllist throwsArgumentNullException; they used to throwTargetExceptionandNullReferenceException.ToTitleCaselower-cases with the invariant culture, so under Turkish or Azerbaijani settings it keeps the dotted i, where it used to give a dotless one. Anullstring throwsArgumentNullExceptioninstead ofNullReferenceException.
Fixes
IEnumerableToDataTableconverts a type with an indexer, a write-only property or a property hidden withnew. These used to throwTargetParameterCountException,ArgumentExceptionandDuplicateNameException, so a list of strings, whose type has an indexer, could not be converted at all.- The
InvalidCastExceptionfromToNonNullableType<T>(false)carries the cause as itsInnerException: aFormatException, anOverflowException, or anArgumentExceptionfor a name an enum does not have. - Text is read with each type's own
TryParseand the stylesConvertuses, so text that does not convert costs no exception, andToNonNullableCollectionTypeconverts each element once instead of twice. 100,000 strings, half of them not numbers, took about 6 ms instead of about 380 ms. The results are the same as before. - The build is deterministic, so the same commit gives the same dll.
Additions
- Overloads of
ToNonNullableType,ToNullableType,IsParseableandToNonNullableCollectionTypetake anIFormatProviderto read text with, such asCultureInfo.InvariantCulturefor text written in a fixed format. The existing methods still read the current culture. - The READMEs are rewritten against the code, with samples that compile and print what they say, and the nuget.org readme is the full README. SECURITY.md says what the library does with what it is given and how to convert text you did not create.
- The package is built in CI from the tagged commit, tested on all three frameworks, scanned for vulnerabilities and malware, and published through nuget.org trusted publishing. The GitHub release carries the package's signed build provenance.