-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for nameof
for open generic types, first class span implicit conversions, and implicit lambda parameters with modifiers
#44641
base: main
Are you sure you want to change the base?
Conversation
Let's hold this until the first .NET 10 preview comes out. That will fix the snippets 5000 build, and the new example will compile. |
9c7d77f
to
b519187
Compare
nameof
and open generic typesnameof
and open generic types, and first class span implicit conversions
a3857be
to
2556e03
Compare
@CamSoper This is ready for review. The snippets build will pass once .NET 10 preview 1 is public. I'd like to merge it once that's available. |
|
||
## The `field` keyword | ||
|
||
The [`field`](../language-reference/keywords/field.md) contextual keyword is in C# 13 as a preview feature. The token `field` accesses the compiler synthesized backing field in a property accessor. It enables you to write an accessor body without declaring an explicit backing field in your type declaration. You can declare a body for one or both accessors for a field backed property. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The [`field`](../language-reference/keywords/field.md) contextual keyword is in C# 13 as a preview feature. The token `field` accesses the compiler synthesized backing field in a property accessor. It enables you to write an accessor body without declaring an explicit backing field in your type declaration. You can declare a body for one or both accessors for a field backed property. | |
The [`field`](../language-reference/keywords/field.md) contextual keyword is in C# 14 as a preview feature. The token `field` accesses the compiler-synthesized backing field in a property accessor. It enables you to write an accessor body without declaring an explicit backing field in your type declaration. You can declare a body for one or both accessors for a field backed property. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to see us go a little deeper into field
since it will be one of the marquee features.
The [`field`](../language-reference/keywords/field.md) contextual keyword is in C# 13 as a preview feature. The token `field` accesses the compiler synthesized backing field in a property accessor. It enables you to write an accessor body without declaring an explicit backing field in your type declaration. You can declare a body for one or both accessors for a field backed property. | |
The token `field` enables you to write a property accessor body without declaring an explicit backing field. `field` is replaced with a compiler synthesized backing field. | |
If you previously wrote: | |
```c# | |
Example |
You can now simplify your code to:
Example
You can declare a body for one or both accessors for a field backed property.
The field
contextual keyword also appeared in C# 13 as a preview feature.
b5ff933
to
4f0d3d1
Compare
|
||
- [`nameof` supports unbound generic types](#unbound-generic-types-and-nameof) | ||
|
||
C# 14 includes the [`field`](#the-field-keyword) contextual keyword as a preview feature. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just a normal preview feature I think. Not sure why it isn't just part of the list. We expect to release it in C# 14.
|
||
C# 14 includes the following new features. You can try these features using the latest [Visual Studio 2022](https://visualstudio.microsoft.com/vs/preview/) version or the [.NET 10 SDK](https://dotnet.microsoft.com/download/dotnet): | ||
|
||
- [`nameof` supports unbound generic types](#unbound-generic-types-and-nameof) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing implicit span conversion in list.
|
||
## The `field` keyword | ||
|
||
The [`field`](../language-reference/keywords/field.md) contextual keyword is in C# 13 as a preview feature. The token `field` accesses the compiler synthesized backing field in a property accessor. It enables you to write an accessor body without declaring an explicit backing field in your type declaration. You can declare a body for one or both accessors for a field backed property. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to see us go a little deeper into field
since it will be one of the marquee features.
The [`field`](../language-reference/keywords/field.md) contextual keyword is in C# 13 as a preview feature. The token `field` accesses the compiler synthesized backing field in a property accessor. It enables you to write an accessor body without declaring an explicit backing field in your type declaration. You can declare a body for one or both accessors for a field backed property. | |
The token `field` enables you to write a property accessor body without declaring an explicit backing field. `field` is replaced with a compiler synthesized backing field. | |
If you previously wrote: | |
```c# | |
Example |
You can now simplify your code to:
Example
You can declare a body for one or both accessors for a field backed property.
The field
contextual keyword also appeared in C# 13 as a preview feature.
|
||
If you try this feature and have feedback, add it to the [feature issue](https://github.com/dotnet/csharplang/issues/140) in the `csharplang` repository. | ||
|
||
## Implicit span conversions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to develop a plan for what happens when we rename a feature between inception and release. I like your new name much better, but wonder if we lose continuity if we don't add it to the Feature Status page. And AKA in the first column?
Obviously, we need to include Julien in that. This is a good example for us to work with.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I picked this as it seemed the bulk of the new language feature was on the additional conversions and conversion priority.
|
||
## Implicit span conversions | ||
|
||
C# 14 introduces first-class support for <xref:System.Span`1?displayProperty=fullName> and <xref:System.ReadOnlySpan`1?displayProperty=fullName> in the language. This support involves new implicit conversions allowing more natural programming with these integral types. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that you use the feature status name immediately, but it is subtle.
|
||
## Unbound generic types and nameof | ||
|
||
Beginning with C# 14, the argument to `nameof` can be an unbound generic type. For example, `nameof(List<>)` evaluates to `List`. In earlier versions of C#, only closed generic types, such as `List<int>`, could be used to produce `List`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is produce the best name here? Retrieve?
very small comment
Fixes dotnet#44182 Add that `nameof` now supports open generic types. This is the first C# 14 feature I've added, so create the C# 14 file, and update the language version tables accordingly.
Get this ready for the first preview
Add updates to C# 14 for the First class Span types.
Co-authored-by: Genevieve Warren <[email protected]>
Co-authored-by: Genevieve Warren <[email protected]>
Fixes dotnet#44887 Publish the speclet and update the language reference to allow modifiers on implicitly typed lambda expressions.
4f0d3d1
to
854ccdc
Compare
Co-authored-by: Kathleen Dollard <[email protected]>
nameof
and open generic types, and first class span implicit conversionsnameof
for open generic types, first class span implicit conversions, and implicit lambda parameters with modifiers
nameof
supports unbound generic types #44182: Add thatnameof
now supports open generic types.This is the first C# 14 feature I've added, so create the C# 14 file, and update the language version tables accordingly.
Many of the files that have been updated are updating links and anchors. Major changes are:
=>
) operator defines a lambda expressionis
,as
,typeof
, and castsInternal previews
Toggle expand/collapse
params
modifier on method parameters=>
) operator defines a lambda expressionis
,as
,typeof
, and caststypeof
tonameof
(IDE0082)Note
This table shows preview links for the 30 files with the most changes. For preview links for other files in this PR, select OpenPublishing.Build Details within checks.