|
1 | 1 | --- |
2 | 2 | title: "Attributes interpreted by the compiler: Miscellaneous" |
3 | | -ms.date: 07/26/2024 |
| 3 | +ms.date: 11/22/2024 |
4 | 4 | description: "Learn about attributes that affect code generated by the compiler: the Conditional, Obsolete, AttributeUsage, ModuleInitializer, and SkipLocalsInit attributes." |
5 | 5 | --- |
6 | 6 | # Miscellaneous attributes interpreted by the C# compiler |
@@ -54,9 +54,7 @@ In the following example, the `Obsolete` attribute is applied to class `A` and t |
54 | 54 |
|
55 | 55 | :::code language="csharp" source="snippets/ObsoleteExample.cs" ID="Snippet1" interactive="try-dotnet" ::: |
56 | 56 |
|
57 | | -The string provided as the first argument to the attribute constructor is displayed as part of the warning or error. Two warnings for class `A` are generated: one for the declaration of the class reference, and one for the class constructor. The `Obsolete` attribute can be used without arguments, but including an explanation what to use instead is recommended. |
58 | | - |
59 | | -In C# 10, you can use constant string interpolation and the `nameof` operator to ensure the names match: |
| 57 | +The string provided as the first argument to the attribute constructor is displayed as part of the warning or error. Two warnings for class `A` are generated: one for the declaration of the class reference, and one for the class constructor. The `Obsolete` attribute can be used without arguments, but including an explanation what to use instead is recommended. You can use constant string interpolation and the `nameof` operator to ensure the names match: |
60 | 58 |
|
61 | 59 | :::code language="csharp" source="snippets/ObsoleteExample.cs" id="Snippet2" ::: |
62 | 60 |
|
@@ -165,13 +163,13 @@ You can learn about async method builders by reading about the following builder |
165 | 163 | - <xref:System.Runtime.CompilerServices.AsyncValueTaskMethodBuilder?displayProperty=fullName> |
166 | 164 | - <xref:System.Runtime.CompilerServices.AsyncValueTaskMethodBuilder%601?displayProperty=fullName> |
167 | 165 |
|
168 | | -In C# 10 and later, the `AsyncMethodBuilder` attribute can be applied to an async method to override the builder for that type. |
| 166 | +The `AsyncMethodBuilder` attribute can be applied to an async method to override the builder for that type. |
169 | 167 |
|
170 | 168 | ## `InterpolatedStringHandler` and `InterpolatedStringHandlerArguments` attributes |
171 | 169 |
|
172 | | -Starting with C# 10, you use these attributes to specify that a type is an *interpolated string handler*. The .NET 6 library already includes <xref:System.Runtime.CompilerServices.DefaultInterpolatedStringHandler?displayProperty=nameWithType> for scenarios where you use an interpolated string as the argument for a `string` parameter. You might have other instances where you want to control how interpolated strings are processed. You apply the <xref:System.Runtime.CompilerServices.InterpolatedStringHandlerAttribute?displayProperty=nameWithType> to the type that implements your handler. You apply the <xref:System.Runtime.CompilerServices.InterpolatedStringHandlerArgumentAttribute?displayProperty=nameWithType> to parameters of that type's constructor. |
| 170 | +You use these attributes to specify that a type is an *interpolated string handler*. The .NET 6 library already includes <xref:System.Runtime.CompilerServices.DefaultInterpolatedStringHandler?displayProperty=nameWithType> for scenarios where you use an interpolated string as the argument for a `string` parameter. You might have other instances where you want to control how interpolated strings are processed. You apply the <xref:System.Runtime.CompilerServices.InterpolatedStringHandlerAttribute?displayProperty=nameWithType> to the type that implements your handler. You apply the <xref:System.Runtime.CompilerServices.InterpolatedStringHandlerArgumentAttribute?displayProperty=nameWithType> to parameters of that type's constructor. |
173 | 171 |
|
174 | | -You can learn more about building an interpolated string handler in the C# 10 feature specification for [interpolated string improvements](~/_csharplang/proposals/csharp-10.0/improved-interpolated-strings.md). |
| 172 | +You can learn more about building an interpolated string handler in the feature specification for [interpolated string improvements](~/_csharplang/proposals/csharp-10.0/improved-interpolated-strings.md). |
175 | 173 |
|
176 | 174 | ## `ModuleInitializer` attribute |
177 | 175 |
|
|
0 commit comments