Introduction to the Diagnostics package

The CommunityToolkit.Diagnostics package contains APIs to efficiently validate method parameters and to throw exceptions in faulting code paths. It is meant to be used to help simplify all argument checks and to make them more expressive and easier to read, while at the same time improving codegen quality and performance.

This package can be installed through NuGet, and it has the following multi-targets:

  • .NET Standard 2.0
  • .NET Standard 2.1
  • .NET 6

This means the package can be used on any available runtime (including .NET Framework, .NET Core, UWP, Unity, Xamarin, Uno, Blazor, etc.). The API surface is almost identical in all cases, while the internal implementation can be optimized when newer APIs are available. The Diagnostics package as a whole is meant to be self-contained and extremely small in scope and binary size.

Getting started

To install the package from within Visual Studio:

  1. In Solution Explorer, right-click on the project and select Manage NuGet Packages. Search for CommunityToolkit.Diagnostics and install it.

    NuGet Packages

  2. Add a using or Imports directive to use the new APIs:

    using CommunityToolkit.Diagnostics;
    Imports CommunityToolkit.Diagnostics

Additional resources

You can find more examples in the unit tests.