Skip to content
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 converting an auto-prop to a field-backed property. #76900

Merged
merged 11 commits into from
Jan 24, 2025

Conversation

CyrusNajmabadi
Copy link
Member

@CyrusNajmabadi CyrusNajmabadi commented Jan 24, 2025

Fixes #76899
Fixes #76901

Looks like:

image

@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner January 24, 2025 04:02
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Jan 24, 2025
@@ -41,23 +42,9 @@ protected override bool SupportsReadOnlyProperties(Compilation compilation)
protected override bool SupportsPropertyInitializer(Compilation compilation)
=> compilation.LanguageVersion() >= LanguageVersion.CSharp6;

protected override bool SupportsFieldExpression(Compilation compilation)
=> compilation.LanguageVersion() >= LanguageVersion.Preview;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved to SyntaxFacts, where we have our other checks.

@@ -18,7 +19,7 @@ namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.UseImplicitlyTypedLambd
[Trait(Traits.Feature, Traits.Features.CodeActionsUseImplicitObjectCreation)]
public sealed class UseImplicitlyTypedLambdaExpressionTests
{
private static readonly LanguageVersion CSharp14 = LanguageVersion.Preview;
private static readonly LanguageVersion CSharp14 = LanguageVersionExtensions.CSharpNext;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we use CSharpNext as there's a process where we look for this when adding the actual CSharp14 LangVersion before shpping that release.

CSharpCodeGenerationContextInfo info,
PropertyDeclarationSyntax property,
ExpressionSyntax backingFieldExpression,
CancellationToken cancellationToken)
{
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

view with whitespace off.

M(field);
field = value;
M(p);
p = value;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was a bug fix. when converting these to a full property, 'field' should be replaced with the final field name.

@CyrusNajmabadi CyrusNajmabadi changed the title Convert to full prop should update 'field expressions Add support for converting an auto-prop to a field-backed property. Jan 24, 2025
@CyrusNajmabadi CyrusNajmabadi merged commit d3bf94e into dotnet:main Jan 24, 2025
25 checks passed
@CyrusNajmabadi CyrusNajmabadi deleted the useAutoPropField branch January 24, 2025 09:21
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Jan 24, 2025
@dibarbet dibarbet removed this from the Next milestone Jan 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead VSCode
Projects
None yet
3 participants