diff --git a/src/Features/Core/Portable/InitializeParameter/AbstractInitializeMemberFromParameterCodeRefactoringProviderMemberCreation.cs b/src/Features/Core/Portable/InitializeParameter/AbstractInitializeMemberFromParameterCodeRefactoringProviderMemberCreation.cs index d665cb64c5fbc1fc360a33cea5916e432c0a788f..0621001875f3f828f8ab28032df2779bbd456e3a 100644 --- a/src/Features/Core/Portable/InitializeParameter/AbstractInitializeMemberFromParameterCodeRefactoringProviderMemberCreation.cs +++ b/src/Features/Core/Portable/InitializeParameter/AbstractInitializeMemberFromParameterCodeRefactoringProviderMemberCreation.cs @@ -316,23 +316,19 @@ private static string GenerateUniqueName(IParameterSymbol parameter, ImmutableAr if (statement != null && fieldOrProperty is TSymbol symbol) { - if (before) + var symbolSyntax = symbol.DeclaringSyntaxReferences[0].GetSyntax(cancellationToken); + if (symbolSyntax.Ancestors().Contains(typeDeclaration)) { - var symbolSyntax = symbol.DeclaringSyntaxReferences[0].GetSyntax(cancellationToken); - if (symbolSyntax.Ancestors().Contains(typeDeclaration)) + if (before) { // Found an existing field/property that corresponds to a preceding parameter. // Place ourselves directly after it. return new CodeGenerationOptions(afterThisLocation: symbolSyntax.GetLocation()); } - } - else - { - // Found an existing field/property that corresponds to a following parameter. - // Place ourselves directly before it. - var symbolSyntax = symbol.DeclaringSyntaxReferences[0].GetSyntax(cancellationToken); - if (symbolSyntax.Ancestors().Contains(typeDeclaration)) + else { + // Found an existing field/property that corresponds to a following parameter. + // Place ourselves directly before it. return new CodeGenerationOptions(beforeThisLocation: symbolSyntax.GetLocation()); } }