提交 e1f15cd0 编写于 作者: C Cyrus Najmabadi

Use tuple

上级 45bb7f64
......@@ -146,13 +146,13 @@ protected override async Task<IEnumerable<IFieldSymbol>> GetFieldsAsync(Document
private bool CanEncapsulate(FieldDeclarationSyntax field)
=> field.Parent is TypeDeclarationSyntax;
protected override Tuple<string, string> GeneratePropertyAndFieldNames(IFieldSymbol field)
protected override (string fieldName, string propertyName) GenerateFieldAndPropertyNames(IFieldSymbol field)
{
// Special case: if the field is "new", we will preserve its original name and the new keyword.
if (field.DeclaredAccessibility == Accessibility.Private || IsNew(field))
{
// Create some capitalized version of the field name for the property
return Tuple.Create(field.Name, MakeUnique(GeneratePropertyName(field.Name), field.ContainingType));
return (field.Name, MakeUnique(GeneratePropertyName(field.Name), field.ContainingType));
}
else
{
......@@ -162,7 +162,7 @@ private bool CanEncapsulate(FieldDeclarationSyntax field)
if (newPropertyName == field.Name)
{
// If we wind up with the field's old name, give the field the unique version of its current name.
return Tuple.Create(MakeUnique(GenerateFieldName(field.Name), field.ContainingType), newPropertyName);
return (MakeUnique(GenerateFieldName(field.Name), field.ContainingType), newPropertyName);
}
// Otherwise, ensure the property's name is unique.
......@@ -172,11 +172,11 @@ private bool CanEncapsulate(FieldDeclarationSyntax field)
// If converting the new property's name into a field name results in the old field name, we're done.
if (newFieldName == field.Name)
{
return Tuple.Create(newFieldName, newPropertyName);
return (newFieldName, newPropertyName);
}
// Otherwise, ensure the new field name is unique.
return Tuple.Create(MakeUnique(newFieldName, field.ContainingType), newPropertyName);
return (MakeUnique(newFieldName, field.ContainingType), newPropertyName);
}
}
......
......@@ -150,9 +150,7 @@ private async Task<Result> EncapsulateFieldResultAsync(Document document, TextSp
private async Task<Result> EncapsulateFieldAsync(IFieldSymbol field, Document document, bool updateReferences, CancellationToken cancellationToken)
{
var originalField = field;
var finalNames = GeneratePropertyAndFieldNames(field);
var finalFieldName = finalNames.Item1;
var generatedPropertyName = finalNames.Item2;
var (finalFieldName, generatedPropertyName) = GenerateFieldAndPropertyNames(field);
// Annotate the field declarations so we can find it after rename.
var fieldDeclaration = field.DeclaringSyntaxReferences.First();
......@@ -352,7 +350,7 @@ protected async Task<Solution> AddPropertyAsync(Document document, Solution dest
Formatter.Annotation.AddAnnotationToSymbol(propertySymbol));
}
protected abstract Tuple<string, string> GeneratePropertyAndFieldNames(IFieldSymbol field);
protected abstract (string fieldName, string propertyName) GenerateFieldAndPropertyNames(IFieldSymbol field);
protected Accessibility ComputeAccessibility(Accessibility accessibility, ITypeSymbol type)
{
......
......@@ -100,19 +100,19 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.EncapsulateField
End If
End Function
Protected Overrides Function GeneratePropertyAndFieldNames(field As IFieldSymbol) As Tuple(Of String, String)
Protected Overrides Function GenerateFieldAndPropertyNames(field As IFieldSymbol) As (fieldName As String, propertyName As String)
' If the field is marked shadows, it will keep its name.
If field.DeclaredAccessibility = Accessibility.Private OrElse IsShadows(field) Then
Dim propertyName = GeneratePropertyName(field.Name)
propertyName = MakeUnique(propertyName, field)
Return Tuple.Create(field.Name, propertyName)
Return (field.Name, propertyName)
Else
Dim propertyName = GeneratePropertyName(field.Name)
Dim containingTypeMemberNames = field.ContainingType.GetAccessibleMembersInThisAndBaseTypes(Of ISymbol)(field.ContainingType).Select(Function(s) s.Name)
propertyName = NameGenerator.GenerateUniqueName(propertyName, containingTypeMemberNames.Where(Function(m) m <> field.Name).ToSet(), StringComparer.OrdinalIgnoreCase)
Dim newFieldName = MakeUnique("_" + Char.ToLower(propertyName(0)) + propertyName.Substring(1), field)
Return Tuple.Create(newFieldName, propertyName)
Return (newFieldName, propertyName)
End If
End Function
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册