Skip to content

Commit 17cfa20

Browse files
authored
Edit pass and freshness (.NET) (#623)
edit pass and freshness
1 parent 70a84f6 commit 17cfa20

14 files changed

Lines changed: 174 additions & 206 deletions

File tree

docs/TOC.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
- name: Community Toolkits for .NET
1+
- name: Community toolkits for .NET
22
expanded: true
33
items:
44
- name: Overview
@@ -7,7 +7,7 @@
77
items:
88
- name: Introduction
99
href: introduction.md
10-
- name: Getting Started
10+
- name: Getting started
1111
href: /windows/communitytoolkit/getting-started
1212
- name: MVVM Toolkit
1313
items:
@@ -23,7 +23,7 @@
2323
href: diagnostics/Guard.md
2424
- name: ThrowHelper
2525
href: diagnostics/ThrowHelper.md
26-
- name: High Performance
26+
- name: High performance
2727
items:
2828
- name: Introduction
2929
href: high-performance/Introduction.md
@@ -42,16 +42,16 @@
4242
- name: Ref<T>
4343
href: high-performance/Ref.md
4444
- name: .NET Aspire Community Toolkit
45-
href: /dotnet/aspire/community-toolkit/overview
45+
href: https://github.com/CommunityToolkit/Aspire
4646
- name: Windows Community Toolkit
4747
items:
4848
- name: Introduction
4949
href: windows/index.md
50-
- name: Getting Started
50+
- name: Getting started
5151
href: windows/getting-started.md
5252
- name: Labs
5353
href: https://aka.ms/toolkit/labs/windows
54-
- name: Sample Gallery
54+
- name: Sample gallery
5555
href: https://aka.ms/windowstoolkitapp
5656
- name: .NET MAUI Community Toolkit
5757
href: maui/index.md

docs/diagnostics/Guard.md

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
---
2-
title: Guard
2+
title: Guard class
33
author: Sergio0694
44
description: Helper methods to verify conditions when running code
55
keywords: windows 10, uwp, windows community toolkit, uwp community toolkit, uwp toolkit, debug, net core, net standard
66
dev_langs:
77
- csharp
88
---
99

10-
# Guard
10+
# Guard class
1111

12-
The [Guard](/dotnet/api/microsoft.toolkit.diagnostics.guard) can be used to validate method arguments in a streamlined manner, which is also faster, less verbose, more expressive and less error prone than manually writing checks and throwing exceptions.
12+
Use the [Guard class](/dotnet/api/microsoft.toolkit.diagnostics.guard) to validate method arguments in a streamlined manner. This class is faster, less verbose, more expressive, and less error-prone than manually writing checks and throwing exceptions.
1313

1414
> **Platform APIs:** [`Guard`](/dotnet/api/microsoft.toolkit.diagnostics.guard), [`CallerArgumentExpressionAttribute`](/dotnet/api/system.runtime.compilerservices.callerargumentexpressionattribute)
1515
1616
## How it works
1717

18-
These `Guard` APIs are built with three core principles in mind:
18+
The `Guard` APIs are built with three core principles in mind:
1919

2020
- Being **fast**. To achieve that, all the APIs have been designed to produce as little code as possible in the caller, and each single Guard API will (almost always) be inlined. Furthermore, specialized methods are generated with T4 templates to achieve the most efficient assembly code possible when working with common types (eg. primitive numeric types).
2121
- Being **helpful**. Each `Guard` API produces a detailed exception message that clearly specifies what went wrong, along with additional info (eg. current variable values), when applicable.
2222
- Being **intuitive**. To achieve this, all the `Guard` APIs have expressive and self-explanatory names that make it immediately clear what each API is supposed to do. This shifts the burden of writing checks away from the developers, letting them express conditions using natural language.
2323

2424
## Syntax
2525

26-
Here is a sample method, with some checks being done with explicitly and with manual throw statements:
26+
The following code snippet shows a sample method, with some checks being done explicitly and manual throw statements:
2727

2828
```csharp
2929
public static void SampleMethod(int[] array, int index, Span<int> span, string text)
@@ -55,7 +55,7 @@ public static void SampleMethod(int[] array, int index, Span<int> span, string t
5555
}
5656
```
5757

58-
And here is the same method, but using the new `Guard.APIs` to validate the input arguments:
58+
Here is the same method, but using the `Guard` APIs to validate the input arguments:
5959

6060
```csharp
6161
public static void SampleMethod(int[] array, int index, Span<int> span, string text)
@@ -68,60 +68,60 @@ public static void SampleMethod(int[] array, int index, Span<int> span, string t
6868
}
6969
```
7070

71-
The `Guard` APIs will perform the required checks in the fastest way possible, and will throw the appropriate exception with a well formated message if they fail.
71+
The `Guard` APIs perform the required checks in the fastest way possible, and throw the appropriate exception with a well-formatted message if they fail.
7272

7373
> [!NOTE]
74-
> The `Guard` APIs rely on [`[CallerArgumentExpression]`](/dotnet/csharp/language-reference/proposals/csharp-10.0/caller-argument-expression) to automatically infer the name of the argument being validated. This requires C# 10 to be enabled in the project in use. If you're using a lower version of the language, you will need to manually pass the parameter name, for instance using `nameof()` to refer to it (eg. `Guard.IsNotNull(array, nameof(array)))`).
74+
> The `Guard` APIs rely on [`[CallerArgumentExpression]`](/dotnet/csharp/language-reference/proposals/csharp-10.0/caller-argument-expression) to automatically infer the name of the argument being validated. This requires C# 10 to be enabled in the project. If you're using a lower version of the language, you need to manually pass the parameter name, for instance using `nameof()` to refer to it (for example, `Guard.IsNotNull(array, nameof(array)))`).
7575
7676
## Methods
7777

78-
There are dozens of different APIs and overloads in the `Guard` class, here are a few of them:
78+
There are dozens of different APIs and overloads in the `Guard` class. The following table describes some of them.
7979

8080
### General
8181

82-
| Methods | Return Type | Description |
83-
| -- | -- | -- |
84-
| IsNotNull&lt;T>(T, string) | void | Asserts that the input value is not null |
85-
| IsOfType&lt;T>(object, string) | void | Asserts that the input value is of a specific type |
86-
| IsAssignableToType&lt;T>(object, string) | void | Asserts that the input value can be assigned to a specified type |
87-
| IsReferenceEqualTo&lt;T>(T, T, string) | void | Asserts that the input value must be the same instance as the target value |
88-
| IsTrue(bool, string) | void | Asserts that the input value must be true |
82+
| Methods | Return type | Description |
83+
|-------------------------------|-------------|----------------------------------------------------|
84+
| `IsNotNull<T>(T, string)` | void | Asserts that the input value is not null |
85+
| `IsOfType<T>(object, string)` | void | Asserts that the input value is of a specific type |
86+
| `IsAssignableToType<T>(object, string)` | void | Asserts that the input value can be assigned to a specified type |
87+
| `IsReferenceEqualTo<T>(T, T, string)` | void | Asserts that the input value must be the same instance as the target value |
88+
| `IsTrue(bool, string)` | void | Asserts that the input value must be true |
8989

9090
### Comparisons
9191

92-
| Methods | Return Type | Description |
93-
| -- | -- | -- |
94-
| IsEqualTo&lt;T>(T, T, string) | void | Asserts that the input value must be equal to a specified value |
95-
| IsBitwiseEqualTo&lt;T>(T, T, string) | void | Asserts that the input value must be a bitwise match with a specified value |
96-
| IsLessThan&lt;T>(T, T, string) | void | Asserts that the input value must be less than a specified value |
97-
| IsLessThanOrEqualTo&lt;T>(T, T, string) | void | Asserts that the input value must be less than or equal to a specified value |
98-
| IsInRange&lt;T>(T, T, T, string) | void | Asserts that the input value must be in the [minimum, maximum) range |
99-
| IsBetween&lt;T>(T, T, T, string name) | void | Asserts that the input value must be in the (minimum, maximum) interval |
100-
| IsBetweenOrEqualTo&lt;T>(T, T, T, string name) | void | Asserts that the input value must be in the [minimum, maximum] interval |
92+
| Methods | Return type | Description |
93+
|------------------------------|-------------|-------------|
94+
| `IsEqualTo<T>(T, T, string)` | void | Asserts that the input value must be equal to a specified value |
95+
| `IsBitwiseEqualTo<T>(T, T, string)` | void | Asserts that the input value must be a bitwise match with a specified value |
96+
| `IsLessThan<T>(T, T, string)` | void | Asserts that the input value must be less than a specified value |
97+
| `IsLessThanOrEqualTo<T>(T, T, string)` | void | Asserts that the input value must be less than or equal to a specified value |
98+
| `IsInRange<T>(T, T, T, string)` | void | Asserts that the input value must be in the [minimum, maximum) range |
99+
| `IsBetween<T>(T, T, T, string name)` | void | Asserts that the input value must be in the (minimum, maximum) interval |
100+
| `IsBetweenOrEqualTo<T>(T, T, T, string name)` | void | Asserts that the input value must be in the [minimum, maximum] interval |
101101

102102
### Strings
103103

104-
| Methods | Return Type | Description |
105-
| -- | -- | -- |
106-
| IsNotNullOrEmpty(string, string) | void | Asserts that the input string instance must not be null or empty |
107-
| IsNotNullOrWhiteSpace(string, string) | void | Asserts that the input string instance must not be null or whitespace |
104+
| Methods | Return type | Description |
105+
|------------------------------------|-------------|-------------|
106+
| `IsNotNullOrEmpty(string, string)` | void | Asserts that the input string instance must not be null or empty |
107+
| `IsNotNullOrWhiteSpace(string, string)` | void | Asserts that the input string instance must not be null or whitespace |
108108

109109
### Collections
110110

111-
| Methods | Return Type | Description |
112-
| -- | -- | -- |
113-
| IsNotEmpty&lt;T>(T[], string) | void | Asserts that the input array instance must not be empty |
114-
| HasSizeEqualTo&lt;T>(T[], int, string) | void | Asserts that the input array instance must have a size of a specified value |
115-
| HasSizeAtLeast&lt;T>(T[], int, string) | void | Asserts that the input array must have a size of at least or equal to a specified value |
116-
| IsInRangeFor&lt;T>(int, T[], string) | void | Asserts that the input index is valid for a given array |
117-
| HasSizeLessThanOrEqualTo&lt;T>(T[], T[], string) | void | Asserts that the source array must have a size of less than or equal to that of the destination array |
111+
| Methods | Return type | Description |
112+
|---------------------------------------|-------------|-------------|
113+
| `IsNotEmpty<T>(T[], string)` | void | Asserts that the input array instance must not be empty |
114+
| `HasSizeEqualTo<T>(T[], int, string)` | void | Asserts that the input array instance must have a size of a specified value |
115+
| `HasSizeAtLeast<T>(T[], int, string)` | void | Asserts that the input array must have a size of at least or equal to a specified value |
116+
| `IsInRangeFor<T>(int, T[], string)` | void | Asserts that the input index is valid for a given array |
117+
| `HasSizeLessThanOrEqualTo<T>(T[], T[], string)` | void | Asserts that the source array must have a size of less than or equal to that of the destination array |
118118

119119
### Tasks
120120

121-
| Methods | Return Type | Description |
122-
| -- | -- | -- |
123-
| IsCompleted(Task, string) | void | Asserts that the input task is in a completed state |
124-
| IsNotCanceled(Task, string) | void | Asserts that the input task is not canceled |
121+
| Methods | Return type | Description |
122+
|-------------------------------|-------------|-----------------------------------------------------|
123+
| `IsCompleted(Task, string)` | void | Asserts that the input task is in a completed state |
124+
| `IsNotCanceled(Task, string)` | void | Asserts that the input task is not canceled |
125125

126126
## Examples
127127

docs/diagnostics/Introduction.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
---
22
title: Introduction to the Diagnostics package
3+
ms.date: 03/13/2026
34
author: Sergio0694
45
description: An overview of how to get started with the Diagnostics package and to the APIs it contains
56
keywords: windows 10, uwp, windows community toolkit, uwp community toolkit, uwp toolkit, .net community toolkit, csharp, get started, visual studio, diagnostics, exceptions, contract, net core, net standard
67
---
78

89
# Introduction to the Diagnostics package
910

10-
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.
11+
The [📦 CommunityToolkit.Diagnostics package](https://www.nuget.org/packages/CommunityToolkit.Diagnostics) contains APIs to efficiently validate method parameters and to throw exceptions in faulting code paths. It's 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.
1112

12-
This package can be installed through NuGet, and it has the following multi-targets:
13+
This package can be installed through NuGet, and it has the following multitargets:
1314

1415
- .NET Standard 2.0
15-
- .NET Standard 2.1
16-
- .NET 6
16+
- .NET 8
1717

18-
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.
18+
This means the package can be used on any available runtime (including .NET Framework, .NET, UWP, Unity, Xamarin, Uno, and Blazor). 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.
1919

20-
## Getting started
20+
## Get started
2121

2222
To install the package from within Visual Studio:
2323

@@ -37,4 +37,4 @@ To install the package from within Visual Studio:
3737

3838
## Additional resources
3939

40-
You can find more examples in the [unit tests](https://github.com/CommunityToolkit/dotnet/tree/main/tests/CommunityToolkit.Diagnostics.UnitTests).
40+
You can find more examples in the [unit tests](https://github.com/CommunityToolkit/dotnet/tree/main/tests/CommunityToolkit.Diagnostics.UnitTests).

0 commit comments

Comments
 (0)