Skip to content

Nullability

TJ Lambert edited this page Feb 14, 2022 · 2 revisions

Nullability Work

Binding Files /src/*.cs

When

  • ASAP - there’s nothing blocking us

How

  • the generator handle them using [NullAllowed] attributes
  • xtro report warnings for missing and extra null allowed, based on ObjC headers
    • important: headers are not always 100% accurate so it’s worth checking:
      • git history if we allowed it (and headers disagree) and
      • if we have unit tests for the API (that prove it works)

Manual Bindings /src/**/*.cs

When (pre-condition)

  • For each framework then xtro entries must all be fixed before starting on the manual bindings
    • because doing binding files later would introduce issues (and re-work)
    • Quick-check (for ARKit, empty result means it’s complete)
cd tests/xtro-sharpie
git grep null-allowed *.ignore | grep ARKit

How

  • For all .cs files
    • should have #nullable enable
      • quick check git grep -L "#nullable enable" . inside framework directory, e.g. src/ARKit. No output means every file has the pragma directive
  • build without errors
    • warnaserror is enabled for nullability (so make is all that should be needed)
  • Use ObjCRuntime.ThrowHelper.Throw``**ArgumentNullException** instead of directly throwing
    • it’s a size saving optimization - but it also shows we reviewed the code for nullability
    • quick check: git grep " ArgumentNullException" . inside framework directory, e.g. ARKit. No output means nothing throw an ArgumentNullException manually (without the helper)
  • Replace == null and != null with the newer is null and is not null to avoid using any == or != overrides.
Clone this wiki locally