diff --git a/src/EditorFeatures/CSharpTest/Rename/CSharpInlineRenameServiceTests.cs b/src/EditorFeatures/CSharpTest/Rename/CSharpInlineRenameServiceTests.cs index 4b75641469157..82bcb6202674e 100644 --- a/src/EditorFeatures/CSharpTest/Rename/CSharpInlineRenameServiceTests.cs +++ b/src/EditorFeatures/CSharpTest/Rename/CSharpInlineRenameServiceTests.cs @@ -94,4 +94,32 @@ public class Sampl$$eClass() new SymbolRenameOptions(), CancellationToken.None); } + + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/883")] + public async Task VerifyAnonymousTypeMemberRenameIsAllowed() + { + var markup = """ + using System; + + class Program + { + static void Main(string[] args) + { + var x = new { Pr$$op = 3 }; + Console.WriteLine(x.Prop); + } + } + """; + + using var workspace = TestWorkspace.CreateCSharp(markup, composition: EditorTestCompositions.EditorFeatures); + + var documentId = workspace.Documents.Single().Id; + var document = workspace.CurrentSolution.GetRequiredDocument(documentId); + var inlineRenameService = document.GetRequiredLanguageService(); + MarkupTestFile.GetPosition(markup, out _, out int cursorPosition); + var inlineRenameInfo = await inlineRenameService.GetRenameInfoAsync(document, cursorPosition, CancellationToken.None).ConfigureAwait(false); + + // Verify that rename is allowed (not error) + Assert.True(inlineRenameInfo.CanRename, "Anonymous type member should be renameable"); + } } diff --git a/src/EditorFeatures/Test2/Rename/RenameEngineTests.vb b/src/EditorFeatures/Test2/Rename/RenameEngineTests.vb index 425e5963d0b0b..afa764bec4a69 100644 --- a/src/EditorFeatures/Test2/Rename/RenameEngineTests.vb +++ b/src/EditorFeatures/Test2/Rename/RenameEngineTests.vb @@ -6960,5 +6960,89 @@ class C result.AssertLabeledSpansAre("Complex", "C.Goo{D}(X)", RelatedLocationType.UnresolvedConflict) End Using End Sub + + + + Public Sub RenameAnonymousTypePropertyInDeclaration(host As RenameTestHost) + Using result = RenameEngineResult.Create(_outputHelper, + + + +using System; + +class Program +{ + static void Main(string[] args) + { + var x = new + { + [|$$Prop|] = 3, + args, + }; + + Console.WriteLine(x.[|Prop|]); + Console.WriteLine(x.args); + } +} + + + , host:=host, renameTo:="Property") + End Using + End Sub + + + + Public Sub RenameAnonymousTypePropertyInAccess(host As RenameTestHost) + Using result = RenameEngineResult.Create(_outputHelper, + + + +using System; + +class Program +{ + static void Main(string[] args) + { + var x = new + { + [|Prop|] = 3, + args, + }; + + Console.WriteLine(x.[|$$Prop|]); + Console.WriteLine(x.args); + } +} + + + , host:=host, renameTo:="Property") + End Using + End Sub + + + + Public Sub RenameAnonymousTypePropertyMultipleOccurrences(host As RenameTestHost) + Using result = RenameEngineResult.Create(_outputHelper, + + + +using System; + +class Program +{ + static void Main(string[] args) + { + var x = new { [|$$Name|] = "Test" }; + var y = new { [|Name|] = "Test2" }; + + Console.WriteLine(x.[|Name|]); + Console.WriteLine(y.[|Name|]); + } +} + + + , host:=host, renameTo:="FullName") + End Using + End Sub End Class End Namespace diff --git a/src/Features/Core/Portable/FeaturesResources.resx b/src/Features/Core/Portable/FeaturesResources.resx index 91de537d5bf3a..59e6a301f7c8c 100644 --- a/src/Features/Core/Portable/FeaturesResources.resx +++ b/src/Features/Core/Portable/FeaturesResources.resx @@ -3039,9 +3039,6 @@ Zero-width positive lookbehind assertions are typically used at the beginning of Please resolve errors in your code before renaming this element. - - Renaming anonymous type members is not yet supported. - You cannot rename elements from previous submissions. diff --git a/src/Features/Core/Portable/Rename/SymbolicRenameInfo.cs b/src/Features/Core/Portable/Rename/SymbolicRenameInfo.cs index 294ce95c42d42..fb5850c61b1d1 100644 --- a/src/Features/Core/Portable/Rename/SymbolicRenameInfo.cs +++ b/src/Features/Core/Portable/Rename/SymbolicRenameInfo.cs @@ -198,9 +198,6 @@ private static async Task GetRenameInfoAsync( return new SymbolicRenameInfo(FeaturesResources.You_cannot_rename_this_element); } - if (symbol.Kind == SymbolKind.Property && symbol.ContainingType.IsAnonymousType) - return new SymbolicRenameInfo(FeaturesResources.Renaming_anonymous_type_members_is_not_yet_supported); - if (symbol.IsErrorType()) return new SymbolicRenameInfo(FeaturesResources.Please_resolve_errors_in_your_code_before_renaming_this_element); diff --git a/src/Features/Core/Portable/xlf/FeaturesResources.cs.xlf b/src/Features/Core/Portable/xlf/FeaturesResources.cs.xlf index 105af68d8d63b..ef29c0ff4b6d6 100644 --- a/src/Features/Core/Portable/xlf/FeaturesResources.cs.xlf +++ b/src/Features/Core/Portable/xlf/FeaturesResources.cs.xlf @@ -2575,11 +2575,6 @@ Pozitivní kontrolní výrazy zpětného vyhledávání s nulovou délkou se obv Změna názvu zachycené proměnné z {0} na {1} vyžaduje restartování aplikace. - - Renaming anonymous type members is not yet supported. - Přejmenování členů anonymního typu se zatím nepodporuje. - - Replace '{0}' with '{1}' Místo {0} použijte {1} diff --git a/src/Features/Core/Portable/xlf/FeaturesResources.de.xlf b/src/Features/Core/Portable/xlf/FeaturesResources.de.xlf index d575007a71a90..ed1748a71e6fc 100644 --- a/src/Features/Core/Portable/xlf/FeaturesResources.de.xlf +++ b/src/Features/Core/Portable/xlf/FeaturesResources.de.xlf @@ -2575,11 +2575,6 @@ Positive Lookbehindassertionen mit Nullbreite werden normalerweise am Anfang reg Das Umbenennen einer erfassten Variablen von „{0}“ in „{1}“ erfordert einen Neustart der Anwendung. - - Renaming anonymous type members is not yet supported. - Das Umbenennen von Elementen des Typs anonym wird noch nicht unterstützt. - - Replace '{0}' with '{1}' "{0}" durch "{1}" ersetzen diff --git a/src/Features/Core/Portable/xlf/FeaturesResources.es.xlf b/src/Features/Core/Portable/xlf/FeaturesResources.es.xlf index 4f18ee9667fbb..d68dea68805a5 100644 --- a/src/Features/Core/Portable/xlf/FeaturesResources.es.xlf +++ b/src/Features/Core/Portable/xlf/FeaturesResources.es.xlf @@ -2575,11 +2575,6 @@ Las aserciones de búsqueda retrasada (lookbehind) positivas de ancho cero se us Para cambiar el nombre de una variable capturada, de "{0}" a "{1}" es necesario reiniciar la aplicación. - - Renaming anonymous type members is not yet supported. - Todavía no se puede cambiar el nombre de miembros de tipo anónimo. - - Replace '{0}' with '{1}' Reemplazar "{0}" por "{1}" diff --git a/src/Features/Core/Portable/xlf/FeaturesResources.fr.xlf b/src/Features/Core/Portable/xlf/FeaturesResources.fr.xlf index 9d79c5d12966c..60e3ef3e8d372 100644 --- a/src/Features/Core/Portable/xlf/FeaturesResources.fr.xlf +++ b/src/Features/Core/Portable/xlf/FeaturesResources.fr.xlf @@ -2575,11 +2575,6 @@ Les assertions arrière positives de largeur nulle sont généralement utilisée Le changement de nom d’une variable capturée, de « {0} » à « {1} », requiert le redémarrage de l’application. - - Renaming anonymous type members is not yet supported. - Le changement de nom des membres de type anonyme n'est pas encore pris en charge. - - Replace '{0}' with '{1}' Remplacer '{0}' par '{1}' diff --git a/src/Features/Core/Portable/xlf/FeaturesResources.it.xlf b/src/Features/Core/Portable/xlf/FeaturesResources.it.xlf index 58bb39b99dffe..dc31ef65ae0e1 100644 --- a/src/Features/Core/Portable/xlf/FeaturesResources.it.xlf +++ b/src/Features/Core/Portable/xlf/FeaturesResources.it.xlf @@ -2575,11 +2575,6 @@ Le asserzioni lookbehind positive di larghezza zero vengono usate in genere all' Se si rinomina una variabile catturata da '{0}' a '{1}', è necessario riavviare l'applicazione. - - Renaming anonymous type members is not yet supported. - La ridenominazione di membri con tipo anonimo non è ancora supportata. - - Replace '{0}' with '{1}' Sostituisci '{0}' con '{1}' diff --git a/src/Features/Core/Portable/xlf/FeaturesResources.ja.xlf b/src/Features/Core/Portable/xlf/FeaturesResources.ja.xlf index d7bd998089a59..a688d368e9a85 100644 --- a/src/Features/Core/Portable/xlf/FeaturesResources.ja.xlf +++ b/src/Features/Core/Portable/xlf/FeaturesResources.ja.xlf @@ -2575,11 +2575,6 @@ Zero-width positive lookbehind assertions are typically used at the beginning of キャプチャした変数の名前を '{0}' から '{1}' に変更するには、アプリケーションを再起動する必要があります。 - - Renaming anonymous type members is not yet supported. - 匿名型メンバーの名前の変更は、まだサポートされていません。 - - Replace '{0}' with '{1}' '{0}' を '{1}' に置き換える diff --git a/src/Features/Core/Portable/xlf/FeaturesResources.ko.xlf b/src/Features/Core/Portable/xlf/FeaturesResources.ko.xlf index 406c90dcc7a60..6b6a1875ac370 100644 --- a/src/Features/Core/Portable/xlf/FeaturesResources.ko.xlf +++ b/src/Features/Core/Portable/xlf/FeaturesResources.ko.xlf @@ -2575,11 +2575,6 @@ Zero-width positive lookbehind assertions are typically used at the beginning of 캡처된 변수의 이름을 '{0}'에서 '{1}'(으)로 바꾸려면 응용 프로그램을 다시 시작해야 합니다. - - Renaming anonymous type members is not yet supported. - 익명 형식의 멤버 이름은 아직 바꿀 수 없습니다. - - Replace '{0}' with '{1}' '{0}'을(를) '{1}'(으)로 바꾸기 diff --git a/src/Features/Core/Portable/xlf/FeaturesResources.pl.xlf b/src/Features/Core/Portable/xlf/FeaturesResources.pl.xlf index 4fee08df99525..02d461d647254 100644 --- a/src/Features/Core/Portable/xlf/FeaturesResources.pl.xlf +++ b/src/Features/Core/Portable/xlf/FeaturesResources.pl.xlf @@ -2575,11 +2575,6 @@ Pozytywne asercje wsteczne o zerowej szerokości są zwykle używane na początk Zmienianie nazwy przechwyconej zmiennej z "{0}" na "{1}" wymaga ponownego uruchomienia aplikacji. - - Renaming anonymous type members is not yet supported. - Zmienianie nazwy anonimowych składowych typu nie jest jeszcze obsługiwane. - - Replace '{0}' with '{1}' Zamień element „{0}” na element „{1}” diff --git a/src/Features/Core/Portable/xlf/FeaturesResources.pt-BR.xlf b/src/Features/Core/Portable/xlf/FeaturesResources.pt-BR.xlf index e6454321315c2..ec3b18afc9683 100644 --- a/src/Features/Core/Portable/xlf/FeaturesResources.pt-BR.xlf +++ b/src/Features/Core/Portable/xlf/FeaturesResources.pt-BR.xlf @@ -2575,11 +2575,6 @@ As declarações de lookbehind positivas de largura zero normalmente são usadas Renomear uma variável capturada de '{0}' para '{1}' requer a reinicialização do aplicativo. - - Renaming anonymous type members is not yet supported. - Renomear membros de tipo anônimo ainda não é suportado. - - Replace '{0}' with '{1}' Substituir '{0}' por '{1}' diff --git a/src/Features/Core/Portable/xlf/FeaturesResources.ru.xlf b/src/Features/Core/Portable/xlf/FeaturesResources.ru.xlf index cf2e1a81c1bd9..0217e9f0fcf25 100644 --- a/src/Features/Core/Portable/xlf/FeaturesResources.ru.xlf +++ b/src/Features/Core/Portable/xlf/FeaturesResources.ru.xlf @@ -2575,11 +2575,6 @@ Zero-width positive lookbehind assertions are typically used at the beginning of Для переименования зафиксированной переменной из "{0}" в "{1}" требуется перезапустить приложение. - - Renaming anonymous type members is not yet supported. - Переименование членов анонимного типа еще не поддерживается. - - Replace '{0}' with '{1}' Замените '{0}' на '{1}' diff --git a/src/Features/Core/Portable/xlf/FeaturesResources.tr.xlf b/src/Features/Core/Portable/xlf/FeaturesResources.tr.xlf index fd8404764d817..0588fad15f471 100644 --- a/src/Features/Core/Portable/xlf/FeaturesResources.tr.xlf +++ b/src/Features/Core/Portable/xlf/FeaturesResources.tr.xlf @@ -2575,11 +2575,6 @@ Sıfır genişlikli pozitif geri yönlü onaylamalar genellikle normal ifadeleri Yakalanan bir değişkenin '{0}' iken '{1}' olarak yeniden adlandırılması, uygulamanın yeniden başlatılmasını gerektirir. - - Renaming anonymous type members is not yet supported. - Anonim türdeki üyeleri yeniden adlandırma henüz desteklenmiyor. - - Replace '{0}' with '{1}' '{0}' öğesini '{1}' ile değiştir diff --git a/src/Features/Core/Portable/xlf/FeaturesResources.zh-Hans.xlf b/src/Features/Core/Portable/xlf/FeaturesResources.zh-Hans.xlf index a1b991b4c986e..ddd6c05c3a416 100644 --- a/src/Features/Core/Portable/xlf/FeaturesResources.zh-Hans.xlf +++ b/src/Features/Core/Portable/xlf/FeaturesResources.zh-Hans.xlf @@ -2575,11 +2575,6 @@ Zero-width positive lookbehind assertions are typically used at the beginning of 将捕获的变量从“{0}”重命名为“{1}”需要重新启动应用程序。 - - Renaming anonymous type members is not yet supported. - 尚不支持重命名匿名类型成员。 - - Replace '{0}' with '{1}' 将 "{0}" 替换为 "{1}" diff --git a/src/Features/Core/Portable/xlf/FeaturesResources.zh-Hant.xlf b/src/Features/Core/Portable/xlf/FeaturesResources.zh-Hant.xlf index f1e1ffd6315d3..0a95402f51f98 100644 --- a/src/Features/Core/Portable/xlf/FeaturesResources.zh-Hant.xlf +++ b/src/Features/Core/Portable/xlf/FeaturesResources.zh-Hant.xlf @@ -2575,11 +2575,6 @@ Zero-width positive lookbehind assertions are typically used at the beginning of 將擷取到的變數從 '{0}' 重新命名為 '{1}' 需要重新啟動應用程式。 - - Renaming anonymous type members is not yet supported. - 目前尚不支援重新命名匿名類型成員。 - - Replace '{0}' with '{1}' 將 ‘{0}’ 取代為 ‘{1}'