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:
In Solution Explorer, right-click on the project and select Manage NuGet Packages. Search for CommunityToolkit.Diagnostics and install it.
Add a using or Imports directive to use the new APIs:
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.
.NET Community Toolkit feedback
.NET Community Toolkit is an open source project. Select a link to provide feedback:
This module guides you through the code verification process for a C# console application. Hands-on activities provide experience identifying logic issues, debugging the application, and implementing exception handling. Step-by-step instructions are provided.