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

Use implicit initializer if present to generate type properties #76162

Merged
merged 3 commits into from
Dec 2, 2024

Conversation

CyrusNajmabadi
Copy link
Member

Fixes #58495

@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner November 29, 2024 21:44
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Nov 29, 2024
// Check for `NewType t = new() { ... }` and initialize properties if present
if (nameOrMemberAccessExpression.Parent is VariableDeclarationSyntax
{
Variables: [{ Initializer.Value: ImplicitObjectCreationExpressionSyntax { Initializer: { } implicitInitializer } }, ..]
Copy link
Contributor

Choose a reason for hiding this comment

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

Variables

Dumb question: Is there any reason we choose the first one? Would it make sense to not enable if more than one variable (or if more than one, only enable if they have the same initialized properties)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Goal here is to not go to down the rabbit hole of potential cases to support.

Copy link
Contributor

Choose a reason for hiding this comment

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

chatted offline, Cyrus is being lazy :)

Copy link
Contributor

@ToddGrun ToddGrun left a comment

Choose a reason for hiding this comment

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

:shipit:

@CyrusNajmabadi CyrusNajmabadi merged commit ce5ba07 into dotnet:main Dec 2, 2024
25 checks passed
@CyrusNajmabadi CyrusNajmabadi deleted the genTypeFromInitializer branch December 2, 2024 20:51
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Dec 2, 2024
@dibarbet dibarbet modified the milestones: Next, 17.13 P3 Jan 7, 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
Development

Successfully merging this pull request may close these issues.

Generate type should take into account the initializer to initialize fields/props as well.
3 participants