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

Update 'initialize member from parameter' to work with primary constructors. #69072

Merged
merged 59 commits into from
Jul 18, 2023

Conversation

CyrusNajmabadi
Copy link
Member

@CyrusNajmabadi CyrusNajmabadi commented Jul 17, 2023

Fixes #68817

Looks like this:

image

QOL for people using primary constructors. Just like witha normal constructor, we want to make it easy to be writing the constructor and then have the user go and create fields/props easily.

Fixes #68817

@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner July 17, 2023 20:58
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Jul 17, 2023
@@ -56,55 +56,10 @@ protected override SyntaxNode GetBody(SyntaxNode functionDeclaration)
=> InitializeParameterHelpers.GetBody(functionDeclaration);

protected override SyntaxNode? GetAccessorBody(IMethodSymbol accessor, 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.

moved to common helper locations.

@@ -314,19 +316,6 @@ internal abstract partial class AbstractInitializeMemberFromParameterCodeRefacto
throw ExceptionUtilities.Unreachable();
}

private static string GenerateUniqueName(IParameterSymbol parameter, ImmutableArray<string> parameterNameParts, NamingRule rule)
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 common helper location.

Copy link
Member Author

Choose a reason for hiding this comment

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

same with the other deletions in the file

{
internal static class InitializeParameterHelpersCore
{
public static ImmutableArray<(IParameterSymbol parameter, bool before)> GetSiblingParameters(IParameterSymbol parameter)
Copy link
Member Author

Choose a reason for hiding this comment

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

these are just moves of helpers.

@@ -138,5 +142,86 @@ public static bool IsExpressionBody(SyntaxNode body)
_ => throw ExceptionUtilities.UnexpectedValue(body),
};
}

public static SyntaxNode? GetAccessorBody(IMethodSymbol accessor, 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.

these are just moves of helpers.

var outParameters = parameterList.Parameters
.Select(p => semanticModel.GetRequiredDeclaredSymbol(p, cancellationToken))
.Where(p => p.RefKind == RefKind.Out)
.ToImmutableArray();
Copy link
Member Author

Choose a reason for hiding this comment

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

cast removed as this now uses a typesafe extension.

@CyrusNajmabadi CyrusNajmabadi merged commit 70a05cd into dotnet:main Jul 18, 2023
24 checks passed
@CyrusNajmabadi CyrusNajmabadi deleted the primaryConstructorWork branch July 18, 2023 18:59
@ghost ghost added this to the Next milestone Jul 18, 2023
@allisonchou allisonchou modified the milestones: Next, 17.8 P1 Jul 24, 2023
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

'Create and assign [field|property]' does not work for primary constructor parameters
4 participants