CsvHelper icon indicating copy to clipboard operation
CsvHelper copied to clipboard

Fix remaining nullable warnings

Open Rob-Hague opened this issue 2 years ago • 0 comments

This PR fixes all remaining nullable warnings using a combination of:

  • Annotating members (public included) with ? or nullable attributes
    • Note, on netfx and netstandard, these attributes don't exist so I have added them in NullableAttributes.cs to prevent build failures, but they don't take part in the nullable state analysis
  • Throwing explicit exceptions which would otherwise have been implicit NullReferenceExceptions
  • Adding asserts to make assumptions explicit, e.g validating reflection, which hopefully would fire during test runs if such assumptions have changed
  • Some slight refactors including a few breaking changes:
    • Added protected constructor on MemberMap to ensure non-nullable properties are initialised
    • Changed argument signature of public static TypeConverterOptions.Merge from Merge(params TypeConverterOptions[] sources) to Merge(TypeConverterOptions options, params TypeConverterOptions[] sources) (internal callsites unchanged)
    • Array/Collection/IEnumerable converters now make use of all Names set rather than just the first (I consider this a feature :slightly_smiling_face:)

Otherwise I tried to keep functional changes to a minimum, and to follow https://github.com/dotnet/runtime/blob/main/docs/coding-guidelines/api-guidelines/nullability.md

Comments welcome

Rob-Hague avatar Feb 19 '23 14:02 Rob-Hague