Skip to content

Commit 3be75a1

Browse files
committed
Create "common-tasks"
Create the common tasks section for what had been "How to" articles.
1 parent e8f0bec commit 3be75a1

20 files changed

Lines changed: 58 additions & 51 deletions

File tree

.openpublishing.redirection.csharp.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,10 @@
648648
"source_path_from_root": "/docs/csharp/features.md",
649649
"redirect_url": "/dotnet/csharp/programming-guide/concepts"
650650
},
651+
{
652+
"source_path_from_root": "/docs/csharp/fundamentals/null-safety/resolve-warnings.md",
653+
"redirect_url": "/dotnet/csharp/fundamentals/null-safety/common-tasks/resolve-warnings"
654+
},
651655
{
652656
"source_path_from_root": "/docs/csharp/generics.md",
653657
"redirect_url": "/dotnet/csharp/fundamentals/types/generics"

docs/csharp/advanced-topics/update-applications/nullable-migration-strategies.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ ai-usage: ai-assisted
99
# Nullable migration strategies
1010

1111
> [!TIP]
12-
> **Starting a new project?** New projects created from .NET 6 or later templates already have `<Nullable>enable</Nullable>` set. You don't need a migration strategy: skip to [Resolve nullable warnings](../../fundamentals/null-safety/resolve-warnings.md).
12+
> **Starting a new project?** New projects created from .NET 6 or later templates already have `<Nullable>enable</Nullable>` set. You don't need a migration strategy: skip to [Resolve nullable warnings](../../fundamentals/null-safety/common-tasks/resolve-warnings.md).
1313
>
1414
> **Maintaining an existing codebase?** Read [Nullable reference types](../../fundamentals/null-safety/nullable-reference-types.md) first to understand contexts, annotations, and null-state. This article assumes you're familiar with those concepts and ready to plan a rollout.
1515
@@ -49,7 +49,7 @@ The most predictable way to migrate a large project is to enable warnings or ann
4949

5050
1. Pick a file. Start with the deepest leaf types in your dependency graph, then move outward. Annotating a type causes new warnings in its callers, so working bottom-up minimizes rework.
5151
1. Add the `#nullable` directive that opts the file into the new behavior. Use `#nullable enable` if you want both flags. Use `#nullable enable warnings` for warning-only.
52-
1. Address the warnings in the file using the techniques in [Resolve nullable warnings](../../fundamentals/null-safety/resolve-warnings.md).
52+
1. Address the warnings in the file using the techniques in [Resolve nullable warnings](../../fundamentals/null-safety/common-tasks/resolve-warnings.md).
5353
1. Repeat for the next file.
5454
1. When every file in the project has its directive, remove the directives and set `<Nullable>enable</Nullable>` at the project level.
5555

@@ -71,7 +71,7 @@ Lead with warnings when fixing latent <xref:System.NullReferenceException?displa
7171
Lead with annotations when stabilizing the public API surface is the priority. This sequence suits libraries: you can ship annotated signatures so consumers see the right contracts, then close out the internal warnings on your own schedule.
7272

7373
1. **Phase 1: Add annotations.** Set the project default to `annotations`. Reference types become non-nullable by default, but the compiler doesn't emit warnings, so the noise stays out of your way. Walk the public API and add `?` to every member that may legitimately return or accept `null`. Tighten the signatures that shouldn't. Because warnings are off, you can settle the API shape in focused commits without untangling the implementation at the same time.
74-
1. **Phase 2: Address warnings.** Switch the project default to `enable`. The annotations you added in phase 1 now feed null-state analysis, so the warnings the compiler emits are higher quality from the start: each one points at code whose behavior doesn't match the contract you already published. Resolve them with the techniques in [Resolve nullable warnings](../../fundamentals/null-safety/resolve-warnings.md).
74+
1. **Phase 2: Address warnings.** Switch the project default to `enable`. The annotations you added in phase 1 now feed null-state analysis, so the warnings the compiler emits are higher quality from the start: each one points at code whose behavior doesn't match the contract you already published. Resolve them with the techniques in [Resolve nullable warnings](../../fundamentals/null-safety/common-tasks/resolve-warnings.md).
7575

7676
### Choosing between the orderings
7777

@@ -96,11 +96,11 @@ After every file participates in the project default and the `<Nullable>enable</
9696
- Remove `null!` and `default!` initializers that you added only to silence warnings during migration. Replace them with proper initialization, or make type a nullable reference type.
9797
- Spot-check the public API. Every member that returns or accepts `null` should be annotated with `?`. The annotations are part of your contract once the package ships.
9898

99-
You're now in the same state as new projects: nullable reference types are part of the type system, and any new warnings reflect a real mismatch between declarations and code. Use [Resolve nullable warnings](../../fundamentals/null-safety/resolve-warnings.md) to address them as they come up.
99+
You're now in the same state as new projects: nullable reference types are part of the type system, and any new warnings reflect a real mismatch between declarations and code. Use [Resolve nullable warnings](../../fundamentals/null-safety/common-tasks/resolve-warnings.md) to address them as they come up.
100100

101101
## Related content
102102

103103
- [Nullable reference types](../../fundamentals/null-safety/nullable-reference-types.md)
104-
- [Resolve nullable warnings](../../fundamentals/null-safety/resolve-warnings.md)
104+
- [Resolve nullable warnings](../../fundamentals/null-safety/common-tasks/resolve-warnings.md)
105105
- [Nullable static analysis attributes](../../language-reference/attributes/nullable-analysis.md)
106106
- [Working with nullable reference types in EF Core](/ef/core/miscellaneous/nullable-reference-types)

docs/csharp/fundamentals/null-safety/resolve-warnings.md renamed to docs/csharp/fundamentals/null-safety/common-tasks/resolve-warnings.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ ai-usage: ai-assisted
99
# Resolve nullable warnings
1010

1111
> [!TIP]
12-
> **New to nullable reference types?** Read [Nullable reference types](nullable-reference-types.md) first to understand annotations and null-state analysis. This article assumes you're seeing warnings in a project where the feature is enabled.
12+
> **New to nullable reference types?** Read [Nullable reference types](../nullable-reference-types.md) first to understand annotations and null-state analysis. This article assumes you're seeing warnings in a project where the feature is enabled.
1313
>
14-
> **Looking for a specific compiler error code?** The [Resolve nullable warnings](../../language-reference/compiler-messages/nullable-warnings.md) reference article catalogs every CS86xx warning with the matching technique.
14+
> **Looking for a specific compiler error code?** The [Resolve nullable warnings](../../../language-reference/compiler-messages/nullable-warnings.md) reference article catalogs every CS86xx warning with the matching technique.
1515
1616
When you enable nullable reference types, the compiler issues warnings everywhere your code's behavior doesn't match its annotations. Most warnings fall into a small set of patterns. Once you recognize the pattern, the fix is usually one of five techniques:
1717

@@ -42,13 +42,13 @@ The fix is usually a *guard clause*. A *guard clause* is a check at the top of a
4242

4343
:::code language="csharp" source="snippets/resolve-warnings/Program.cs" id="DereferenceFixed":::
4444

45-
[Pattern matching](../../language-reference/operators/patterns.md) (expressions such as `is null` or `is { }` that test the shape of a value), `??`, and `??=` include null checks:
45+
[Pattern matching](../../../language-reference/operators/patterns.md) (expressions such as `is null` or `is { }` that test the shape of a value), `??`, and `??=` include null checks:
4646

4747
:::code language="csharp" source="snippets/resolve-warnings/Program.cs" id="NullOperatorsFix":::
4848

4949
The property pattern `{ Length: > 0 }` matches only when `message` is non-null *and* its `Length` property is greater than zero, so the compiler treats `message` as *not-null* inside the `if` block. A simpler `is not null` test produces the same null-state narrowing without inspecting any properties.
5050

51-
For an in-depth tour of the operators, see [Null operators](null-operators.md).
51+
For an in-depth tour of the operators, see [Null operators](../null-operators.md).
5252

5353
## Adjust annotations
5454

@@ -73,7 +73,7 @@ Sometimes the right fix isn't at the call site. A method's signature doesn't cap
7373

7474
:::code language="csharp" source="snippets/resolve-warnings/Program.cs" id="MissingAttribute":::
7575

76-
The body of `IsPresent` proves the argument isn't null when the method returns `true`, but the signature doesn't say so. Add a [nullable analysis attribute](../../language-reference/attributes/nullable-analysis.md) to make the contract part of the API:
76+
The body of `IsPresent` proves the argument isn't null when the method returns `true`, but the signature doesn't say so. Add a [nullable analysis attribute](../../../language-reference/attributes/nullable-analysis.md) to make the contract part of the API:
7777

7878
:::code language="csharp" source="snippets/resolve-warnings/Program.cs" id="WithAttribute":::
7979

@@ -84,21 +84,21 @@ Common attributes include:
8484
- <xref:System.Diagnostics.CodeAnalysis.MemberNotNullAttribute> — the listed members are *not-null* after the method returns.
8585
- <xref:System.Diagnostics.CodeAnalysis.DoesNotReturnAttribute> — the method never returns normally (for example, it always throws).
8686

87-
The full list is in [Nullable static analysis attributes](../../language-reference/attributes/nullable-analysis.md).
87+
The full list is in [Nullable static analysis attributes](../../../language-reference/attributes/nullable-analysis.md).
8888

8989
## Initialize non-nullable members
9090

91-
A constructor warning means a non-nullable field, property, or [auto-property](../../programming-guide/classes-and-structs/auto-implemented-properties.md) (a property that uses the compiler-generated backing field, such as `public string Name { get; set; }`) exits the constructor without being assigned a non-null value:
91+
A constructor warning means a non-nullable field, property, or [auto-property](../../../programming-guide/classes-and-structs/auto-implemented-properties.md) (a property that uses the compiler-generated backing field, such as `public string Name { get; set; }`) exits the constructor without being assigned a non-null value:
9292

9393
:::code language="csharp" source="snippets/resolve-warnings/Program.cs" id="UninitializedMember":::
9494

9595
You have several ways to address it. Pick the one that best matches your design intent.
9696

97-
**Require the value as a constructor argument.** Use a [primary constructor](../../whats-new/tutorials/primary-constructors.md) (parameters declared on the type itself, available throughout the body) or a regular constructor that initializes the property:
97+
**Require the value as a constructor argument.** Use a [primary constructor](../../../whats-new/tutorials/primary-constructors.md) (parameters declared on the type itself, available throughout the body) or a regular constructor that initializes the property:
9898

9999
:::code language="csharp" source="snippets/resolve-warnings/Program.cs" id="ConstructorInjected":::
100100

101-
**Make the property `required`.** The caller must initialize it through an [object initializer](../../programming-guide/classes-and-structs/object-and-collection-initializers.md) (the `{ Property = value }` syntax that follows `new`):
101+
**Make the property `required`.** The caller must initialize it through an [object initializer](../../../programming-guide/classes-and-structs/object-and-collection-initializers.md) (the `{ Property = value }` syntax that follows `new`):
102102

103103
:::code language="csharp" source="snippets/resolve-warnings/Program.cs" id="RequiredMember":::
104104

@@ -123,18 +123,18 @@ New C# projects enable nullable reference types by default, so most code you wri
123123

124124
The common supported values are `enable` (the default for new projects) and `disable`. If the element is missing, the project uses whatever default the SDK and target framework set.
125125

126-
If you need to enable nullable for only part of a file with `#nullable` directives, or use the partial `warnings` and `annotations` modes when migrating an existing codebase, see [Nullable migration strategies](../../advanced-topics/update-applications/nullable-migration-strategies.md).
126+
If you need to enable nullable for only part of a file with `#nullable` directives, or use the partial `warnings` and `annotations` modes when migrating an existing codebase, see [Nullable migration strategies](../../../advanced-topics/update-applications/nullable-migration-strategies.md).
127127

128128
## Where to go next
129129

130-
When a warning doesn't fit any of these patterns, the [Resolve nullable warnings](../../language-reference/compiler-messages/nullable-warnings.md) reference article lists the technique for every CS86xx warning the compiler emits.
130+
When a warning doesn't fit any of these patterns, the [Resolve nullable warnings](../../../language-reference/compiler-messages/nullable-warnings.md) reference article lists the technique for every CS86xx warning the compiler emits.
131131

132-
To plan a migration that progressively enables nullable reference types in an existing codebase, see [Nullable migration strategies](../../advanced-topics/update-applications/nullable-migration-strategies.md).
132+
To plan a migration that progressively enables nullable reference types in an existing codebase, see [Nullable migration strategies](../../../advanced-topics/update-applications/nullable-migration-strategies.md).
133133

134134
## Related content
135135

136-
- [Nullable reference types](nullable-reference-types.md)
137-
- [Null operators](null-operators.md)
138-
- [Nullable migration strategies](../../advanced-topics/update-applications/nullable-migration-strategies.md)
139-
- [Nullable static analysis attributes](../../language-reference/attributes/nullable-analysis.md)
140-
- [Resolve nullable warnings (compiler reference)](../../language-reference/compiler-messages/nullable-warnings.md)
136+
- [Nullable reference types](../nullable-reference-types.md)
137+
- [Null operators](../null-operators.md)
138+
- [Nullable migration strategies](../../../advanced-topics/update-applications/nullable-migration-strategies.md)
139+
- [Nullable static analysis attributes](../../../language-reference/attributes/nullable-analysis.md)
140+
- [Resolve nullable warnings (compiler reference)](../../../language-reference/compiler-messages/nullable-warnings.md)

docs/csharp/fundamentals/null-safety/snippets/resolve-warnings/Program.cs renamed to docs/csharp/fundamentals/null-safety/common-tasks/snippets/resolve-warnings/Program.cs

File renamed without changes.

docs/csharp/fundamentals/null-safety/snippets/resolve-warnings/project-snippet.xml renamed to docs/csharp/fundamentals/null-safety/common-tasks/snippets/resolve-warnings/project-snippet.xml

File renamed without changes.

docs/csharp/fundamentals/null-safety/snippets/resolve-warnings/resolve-warnings.csproj renamed to docs/csharp/fundamentals/null-safety/common-tasks/snippets/resolve-warnings/resolve-warnings.csproj

File renamed without changes.

docs/csharp/fundamentals/null-safety/nullable-reference-types.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ Initialize array elements as part of creating the array. [Collection expressions
110110
## Related content
111111

112112
- [Tutorial: Express your design intent with nullable and non-nullable reference types](../tutorials/nullable-reference-types.md)
113-
- [Resolve nullable warnings](resolve-warnings.md)
113+
- [Resolve nullable warnings](./common-tasks/resolve-warnings.md)
114114
- [Nullable migration strategies](../../advanced-topics/update-applications/nullable-migration-strategies.md)
115115
- [Nullable static analysis attributes](../../language-reference/attributes/nullable-analysis.md)
116116
- [Resolve nullable warnings (compiler reference)](../../language-reference/compiler-messages/nullable-warnings.md)

docs/csharp/fundamentals/strings/search.md renamed to docs/csharp/fundamentals/strings/common-tasks/search.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ ai-usage: ai-assisted
99
# Search strings in C\#
1010

1111
> [!TIP]
12-
> This article is part of the **Fundamentals** section for developers who already know at least one programming language and are learning C#. If you're new to programming, start with the [Get started](../../tour-of-csharp/tutorials/index.md) tutorials first.
12+
> This article is part of the **Fundamentals** section for developers who already know at least one programming language and are learning C#. If you're new to programming, start with the [Get started](../../../tour-of-csharp/tutorials/index.md) tutorials first.
1313
>
1414
> **Coming from another language?** C# `string` methods such as `Contains`, `StartsWith`, and `IndexOf` parallel methods in Java's `String` and JavaScript's `String.prototype`. The key difference is that some C# searches default to **ordinal, case-sensitive** comparison. Others default to the current culture's semantics. For user-facing searches, you might want to pass a <xref:System.StringComparison> value.
1515
@@ -18,7 +18,7 @@ The <xref:System.String> class includes methods that answer two everyday questio
1818
- *Does this string contain that text?* — use <xref:System.String.Contains*>, <xref:System.String.StartsWith*>, or <xref:System.String.EndsWith*>.
1919
- *Where does that text occur?* — use <xref:System.String.IndexOf*> or <xref:System.String.LastIndexOf*>.
2020

21-
For regular expressions, span-based search over `ReadOnlySpan<char>`, and performance considerations, see [String operations](../../language-reference/builtin-types/string-operations.md). For an in-depth treatment of culture-aware comparison, see [Best practices for comparing strings](../../../standard/base-types/best-practices-strings.md).
21+
For regular expressions, span-based search over `ReadOnlySpan<char>`, and performance considerations, see [String operations](../../../language-reference/builtin-types/string-operations.md). For an in-depth treatment of culture-aware comparison, see [Best practices for comparing strings](../../../../standard/base-types/best-practices-strings.md).
2222

2323
## Check whether a string contains text
2424

@@ -54,8 +54,8 @@ Ordinal comparison is the fastest option and the right default for anything that
5454

5555
## See also
5656

57-
- [String operations: pattern matching, performance, and span-based search](../../language-reference/builtin-types/string-operations.md)
58-
- [Best practices for comparing strings in .NET](../../../standard/base-types/best-practices-strings.md)
59-
- [Comparing strings](../../../standard/base-types/comparing.md)
57+
- [String operations: pattern matching, performance, and span-based search](../../../language-reference/builtin-types/string-operations.md)
58+
- [Best practices for comparing strings in .NET](../../../../standard/base-types/best-practices-strings.md)
59+
- [Comparing strings](../../../../standard/base-types/comparing.md)
6060
- <xref:System.String?displayProperty=nameWithType>
6161
- <xref:System.StringComparison?displayProperty=nameWithType>

docs/csharp/fundamentals/strings/snippets/search/Program.cs renamed to docs/csharp/fundamentals/strings/common-tasks/snippets/search/Program.cs

File renamed without changes.

docs/csharp/fundamentals/strings/snippets/search/search.csproj renamed to docs/csharp/fundamentals/strings/common-tasks/snippets/search/search.csproj

File renamed without changes.

0 commit comments

Comments
 (0)