You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
These had two sets of changes:
1. use `csharp` as the language identifier for code fences.
1. use relative links to other articles in the dotnet/csharplang repo that are being published on docs.microsoft.com so those links resolve to the article published there from that site.
We can remove the need for this boilerplate and make it easier to get started simply by allowing Main itself to be
32
34
`async` such that `await`s can be used in it.
33
35
34
36
## Detailed design
35
37
[design]: #detailed-design
36
38
37
39
The following signatures are currently allowed entrypoints:
38
-
```C#
40
+
41
+
```csharp
39
42
staticvoidMain()
40
43
staticvoidMain(string[])
41
44
staticintMain()
42
45
staticintMain(string[])
43
46
```
44
47
45
48
We extend the list of allowed entrypoints to include:
46
-
```
49
+
50
+
```csharp
47
51
staticTaskMain()
48
52
staticTask<int>Main()
49
53
staticTaskMain(string[])
50
54
staticTask<int>Main(string[])
51
55
```
56
+
52
57
To avoid compatibility risks, these new signatures will only be considered as valid entrypoints if no overloads of the previous set are present.
53
58
The language / compiler will not require that the entrypoint be marked as `async`, though we expect the vast majority of uses will be marked as such.
54
59
@@ -59,7 +64,8 @@ When one of these is identified as the entrypoint, the compiler will synthesize
59
64
-```static Task<int> Main(string[])``` will result in the compiler emitting the equivalent of ```private static int $GeneratedMain(string[] args) => Main(args).GetAwaiter().GetResult();```
60
65
61
66
Example usage:
62
-
```C#
67
+
68
+
```csharp
63
69
usingSystem;
64
70
usingSystem.Net.Http;
65
71
@@ -81,14 +87,17 @@ The main drawback is simply the additional complexity of supporting additional e
81
87
Other variants considered:
82
88
83
89
Allowing `async void`. We need to keep the semantics the same for code calling it directly, which would then make it difficult for a generated entrypoint to call it (no Task returned). We could solve this by generating two other methods, e.g.
There are also concerns around encouraging usage of `async void`.
102
112
103
113
Using "MainAsync" instead of "Main" as the name. While the async suffix is recommended for Task-returning methods, that's primarily about library functionality, which Main is not, and supporting additional entrypoint names beyond "Main" is not worth it.
Copy file name to clipboardExpand all lines: proposals/csharp-7.1/generics-pattern-match.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@
8
8
## Summary
9
9
[summary]: #summary
10
10
11
-
The specification for the [existing C# as operator](https://github.com/dotnet/csharplang/blob/master/spec/expressions.md#the-as-operator) permits there to be no conversion between the type of the operand and the specified type when either is an open type. However, in C# 7 the `Type identifier` pattern requires there be a conversion between the type of the input and the given type.
11
+
The specification for the [existing C# as operator](../../spec/expressions.md#the-as-operator) permits there to be no conversion between the type of the operand and the specified type when either is an open type. However, in C# 7 the `Type identifier` pattern requires there be a conversion between the type of the input and the given type.
12
12
13
13
We propose to relax this and change `expression is Type identifier`, in addition to being permitted in the conditions when it is permitted in C# 7, to also be permitted when `expression as Type` would be allowed. Specifically, the new cases are cases where the type of the expression or the specified type is an open type.
@@ -30,7 +30,8 @@ There are two parts to the change:
30
30
Note that the rule for handling duplicates is different than that for anonymous types. For instance, `new { x.f1, x.f1 }` produces an error, but `(x.f1, x.f1)` would still be allowed (just without any inferred names). This avoids breaking existing tuple code.
31
31
32
32
For consistency, the same would apply to tuples produced by deconstruction-assignments (in C#):
33
-
```C#
33
+
34
+
```csharp
34
35
// tuple has element names "f1" and "f2"
35
36
vartuple= ((x.f1, x?.f2) = (1, 2));
36
37
```
@@ -44,7 +45,7 @@ When using the C# 7.1 compiler (or later) with language version "7.0", the eleme
44
45
45
46
The main drawback is that this introduces a compatibility break from C# 7.0:
46
47
47
-
```C#
48
+
```csharp
48
49
Actiony= () =>M();
49
50
vart= (x: x, y);
50
51
t.y(); // this might have previously picked up an extension method called “y”, but would now call the lambda.
0 commit comments