Skip to content

Commit 3eb6117

Browse files
BillWagneradegeo
andauthored
Combine and add expression tree restrictions (#36991)
* Combine and add expression tree restrictions Contributes to #36356 One of the new compiler errors added for collection expressions is that collection expressions are not allowed in expression trees. There are many features in the language that can't be used in expression trees. While adding this new error create a page to handle all the expression tree restrictions. * fix typo in redirection * edit pass and proofread * run clean-repo to fix links. * grammar check. * Apply suggestions from code review Co-authored-by: Andy (Steve) De George <[email protected]> * Update docs/csharp/language-reference/compiler-messages/expression-tree-restrictions.md --------- Co-authored-by: Andy (Steve) De George <[email protected]>
1 parent 22b8030 commit 3eb6117

17 files changed

+237
-558
lines changed

.openpublishing.redirection.csharp.json

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,20 +325,32 @@
325325
},
326326
{
327327
"source_path_from_root": "/docs/csharp/language-reference/compiler-messages/cs0834.md",
328-
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/lambda-expression-errors#conversion-to-expression-trees"
328+
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/expression-tree-restrictions"
329329
},
330330
{
331331
"source_path_from_root": "/docs/csharp/language-reference/compiler-messages/cs0843.md",
332332
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/feature-version-errors"
333333
},
334+
{
335+
"source_path_from_root": "/docs/csharp/language-reference/compiler-messages/cs0845.md",
336+
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/expression-tree-restrictions"
337+
},
334338
{
335339
"source_path_from_root": "/docs/csharp/language-reference/compiler-messages/cs0846.md",
336340
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/array-declaration-errors"
337341
},
342+
{
343+
"source_path_from_root": "/docs/csharp/language-reference/compiler-messages/cs0854.md",
344+
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/expression-tree-restrictions"
345+
},
338346
{
339347
"source_path_from_root": "/docs/csharp/language-reference/compiler-messages/cs1921.md",
340348
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/array-declaration-errors"
341349
},
350+
{
351+
"source_path_from_root": "/docs/csharp/language-reference/compiler-messages/cs1946.md",
352+
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/expression-tree-restrictions"
353+
},
342354
{
343355
"source_path_from_root": "/docs/csharp/language-reference/compiler-messages/cs3007.md",
344356
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/array-declaration-errors"
@@ -1348,6 +1360,10 @@
13481360
"source_path_from_root": "/docs/csharp/misc/cs0748.md",
13491361
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/lambda-expression-errors#lambda-expression-parameters-and-returns"
13501362
},
1363+
{
1364+
"source_path_from_root": "/docs/csharp/misc/cs0765.md",
1365+
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/expression-tree-restrictions"
1366+
},
13511367
{
13521368
"source_path_from_root": "/docs/csharp/misc/cs0820.md",
13531369
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/array-declaration-errors"
@@ -1356,9 +1372,21 @@
13561372
"source_path_from_root": "/docs/csharp/misc/cs0824.md",
13571373
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/constructor-errors#constructor-declarations"
13581374
},
1375+
{
1376+
"source_path_from_root": "/docs/csharp/misc/cs0831.md",
1377+
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/expression-tree-restrictions"
1378+
},
1379+
{
1380+
"source_path_from_root": "/docs/csharp/misc/cs0832.md",
1381+
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/expression-tree-restrictions"
1382+
},
13591383
{
13601384
"source_path_from_root": "/docs/csharp/misc/cs0835.md",
1361-
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/lambda-expression-errors#conversion-to-expression-trees"
1385+
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/expression-tree-restrictions"
1386+
},
1387+
{
1388+
"source_path_from_root": "/docs/csharp/misc/cs0838.md",
1389+
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/expression-tree-restrictions"
13621390
},
13631391
{
13641392
"source_path_from_root": "/docs/csharp/misc/cs1529.md",
@@ -1408,13 +1436,21 @@
14081436
"source_path_from_root": "/docs/csharp/misc/cs1925.md",
14091437
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/array-declaration-errors"
14101438
},
1439+
{
1440+
"source_path_from_root": "/docs/csharp/misc/cs1944.md",
1441+
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/expression-tree-restrictions"
1442+
},
1443+
{
1444+
"source_path_from_root": "/docs/csharp/misc/cs1945.md",
1445+
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/expression-tree-restrictions"
1446+
},
14111447
{
14121448
"source_path_from_root": "/docs/csharp/misc/cs1951.md",
1413-
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/lambda-expression-errors#syntax-limitations-in-lambda-expressions"
1449+
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/expression-tree-restrictions"
14141450
},
14151451
{
14161452
"source_path_from_root": "/docs/csharp/misc/cs1952.md",
1417-
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/lambda-expression-errors#syntax-limitations-in-lambda-expressions"
1453+
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/expression-tree-restrictions"
14181454
},
14191455
{
14201456
"source_path_from_root": "/docs/csharp/misc/cs1953.md",

docs/azure/sdk/dependency-injection.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ In the preceding code:
6262

6363
## Use the registered clients
6464

65-
With the clients registered, as described in the [Register clients and subclients](#register-clients-and-subclients) section, you can now use them. In the following example, [constructor injection](/dotnet/core/extensions/dependency-injection#constructor-injection-behavior) is used to obtain the Blob Storage client in an ASP.NET Core API controller:
65+
With the clients registered, as described in the [Register clients and subclients](#register-clients-and-subclients) section, you can now use them. In the following example, [constructor injection](../../core/extensions/dependency-injection.md#constructor-injection-behavior) is used to obtain the Blob Storage client in an ASP.NET Core API controller:
6666

6767
```csharp
6868
[ApiController]

docs/azure/sdk/unit-testing-mocking.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ When unit testing you only want the unit tests to verify the application logic a
181181

182182
## Refactor your types for testability
183183

184-
Classes that need to be tested should be designed for [dependency injection](/dotnet/azure/sdk/dependency-injection), which allows the class to receive its dependencies instead of creating them internally. It was a seamless process to replace the `SecretClient` implementation in the example from the previous section because it was one of the constructor parameters. However, there may be classes in your code that create their own dependencies and aren't easily testable, such as the following:
184+
Classes that need to be tested should be designed for [dependency injection](dependency-injection.md), which allows the class to receive its dependencies instead of creating them internally. It was a seamless process to replace the `SecretClient` implementation in the example from the previous section because it was one of the constructor parameters. However, there may be classes in your code that create their own dependencies and aren't easily testable, such as the following:
185185

186186
```csharp
187187
public class AboutToExpireSecretFinder

docs/core/deploying/trimming/prepare-libraries-for-trimming.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ Because of the dependency limitations, a self-contained test app which uses the
8585
* The library code.
8686
* The code that the library references from its dependencies.
8787

88-
***Note:*** If the library has different behavior depending on the target framework, create a trimming test app for each of the target frameworks that support trimming. For example, if the library uses [conditional compilation](/dotnet/csharp/language-reference/preprocessor-directives#conditional-compilation) such as `#if NET7_0` to change behavior.
88+
***Note:*** If the library has different behavior depending on the target framework, create a trimming test app for each of the target frameworks that support trimming. For example, if the library uses [conditional compilation](../../../csharp/language-reference/preprocessor-directives.md#conditional-compilation) such as `#if NET7_0` to change behavior.
8989

9090
To create the trimming test app:
9191

@@ -206,7 +206,7 @@ In this case, the trim analysis keeps public methods of <xref:System.Tuple>, and
206206
* When code is incompatible with trimming, annotate it with `RequiresUnreferencedCode` and propagate this annotation to callers until the relevant public APIs are annotated.
207207
* Avoid using code that uses reflection in a way not understood by the static analysis. For example, reflection in static constructors should be avoided. Using statically unanalyzable reflection in static constructors result in the warning propagating to all members of the class.
208208
* Avoid annotating virtual methods or interface methods. Annotating virtual or interface methods requires all overrides to have matching annotations.
209-
* If an API is mostly trim-incompatible, alternative coding approaches to the API may need to be considered. A common example is reflection-based serializers. In these cases, consider adopting other technology like source generators to produce code that is more easily statically analyzed. For example, see [How to use source generation in System.Text.Json](/dotnet/standard/serialization/system-text-json/source-generation)
209+
* If an API is mostly trim-incompatible, alternative coding approaches to the API may need to be considered. A common example is reflection-based serializers. In these cases, consider adopting other technology like source generators to produce code that is more easily statically analyzed. For example, see [How to use source generation in System.Text.Json](../../../standard/serialization/system-text-json/source-generation.md)
210210

211211
## Resolve warnings for non-analyzable patterns
212212

docs/csharp/language-reference/compiler-messages/cs0845.md

Lines changed: 0 additions & 43 deletions
This file was deleted.

docs/csharp/language-reference/compiler-messages/cs0854.md

Lines changed: 0 additions & 43 deletions
This file was deleted.

docs/csharp/language-reference/compiler-messages/cs1946.md

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)