提交 ba93ec6a 编写于 作者: C CyrusNajmabadi

Produce better names for backing fields.

上级 9e692578
...@@ -395,6 +395,19 @@ public async Task TestAutoProperty5() ...@@ -395,6 +395,19 @@ public async Task TestAutoProperty5()
private int prop; private int prop;
private readonly int prop1 = 1; private readonly int prop1 = 1;
public int GetProp() { return this.prop1; } public int GetProp() { return this.prop1; }
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsReplacePropertyWithMethods)]
public async Task TestAutoProperty6()
{
await TestAsync(
@"class C {
public int [||]PascalCase { get; }
}",
@"class C {
private readonly int pascalCase;
public int GetPascalCase() { return this.pascalCase; }
}"); }");
} }
} }
......
...@@ -29,7 +29,7 @@ public override SyntaxNode GetPropertyDeclaration(SyntaxToken token) ...@@ -29,7 +29,7 @@ public override SyntaxNode GetPropertyDeclaration(SyntaxToken token)
? containingProperty.AttributeLists.Last().GetLastToken().GetNextToken().SpanStart ? containingProperty.AttributeLists.Last().GetLastToken().GetNextToken().SpanStart
: containingProperty.SpanStart; : containingProperty.SpanStart;
// Offer this refactoring anywhere in the signature of the method. // Offer this refactoring anywhere in the signature of the property.
var position = token.SpanStart; var position = token.SpanStart;
if (position < start || position > containingProperty.Identifier.Span.End) if (position < start || position > containingProperty.Identifier.Span.End)
{ {
......
...@@ -153,7 +153,7 @@ private static IFieldSymbol GetBackingField(IPropertySymbol property) ...@@ -153,7 +153,7 @@ private static IFieldSymbol GetBackingField(IPropertySymbol property)
// the case for C# where we have mangled names for the backing field and need something // the case for C# where we have mangled names for the backing field and need something
// actually usable in code. // actually usable in code.
var uniqueName = NameGenerator.GenerateUniqueName( var uniqueName = NameGenerator.GenerateUniqueName(
property.Name.ToLowerInvariant(), property.Name.ToCamelCase(),
n => !property.ContainingType.GetMembers(n).Any()); n => !property.ContainingType.GetMembers(n).Any());
return CodeGenerationSymbolFactory.CreateFieldSymbol( return CodeGenerationSymbolFactory.CreateFieldSymbol(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册