From 97f550a15d9be36717ff37e3cad37086c51b496d Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 2 Oct 2019 11:48:47 -0700 Subject: [PATCH] Add UI --- .../Impl/Options/Formatting/StyleViewModel.cs | 33 +++++++++++++++++++ .../Core/Def/ServicesVSResources.Designer.cs | 18 ++++++++++ .../Core/Def/ServicesVSResources.resx | 6 ++++ .../Core/Def/xlf/ServicesVSResources.cs.xlf | 10 ++++++ .../Core/Def/xlf/ServicesVSResources.de.xlf | 10 ++++++ .../Core/Def/xlf/ServicesVSResources.es.xlf | 10 ++++++ .../Core/Def/xlf/ServicesVSResources.fr.xlf | 10 ++++++ .../Core/Def/xlf/ServicesVSResources.it.xlf | 10 ++++++ .../Core/Def/xlf/ServicesVSResources.ja.xlf | 10 ++++++ .../Core/Def/xlf/ServicesVSResources.ko.xlf | 10 ++++++ .../Core/Def/xlf/ServicesVSResources.pl.xlf | 10 ++++++ .../Def/xlf/ServicesVSResources.pt-BR.xlf | 10 ++++++ .../Core/Def/xlf/ServicesVSResources.ru.xlf | 10 ++++++ .../Core/Def/xlf/ServicesVSResources.tr.xlf | 10 ++++++ .../Def/xlf/ServicesVSResources.zh-Hans.xlf | 10 ++++++ .../Def/xlf/ServicesVSResources.zh-Hant.xlf | 10 ++++++ .../Impl/Options/StyleViewModel.vb | 29 ++++++++++++++++ .../Portable/CodeStyle/CodeStyleOptions.cs | 5 +-- 18 files changed, 219 insertions(+), 2 deletions(-) diff --git a/src/VisualStudio/CSharp/Impl/Options/Formatting/StyleViewModel.cs b/src/VisualStudio/CSharp/Impl/Options/Formatting/StyleViewModel.cs index b58affd9b3a..3dcacc8768e 100644 --- a/src/VisualStudio/CSharp/Impl/Options/Formatting/StyleViewModel.cs +++ b/src/VisualStudio/CSharp/Impl/Options/Formatting/StyleViewModel.cs @@ -813,6 +813,38 @@ void Method() }} //] }} +"; + + private static readonly string s_preferSystemHashCode = $@" +using System; + +class Customer1 +{{ + int a, b, c; +//[ + // {ServicesVSResources.Prefer_colon} + // {ServicesVSResources.Requires_System_HashCode_be_present_in_project} + public override int GetHashCode() + {{ + return System.HashCode.Combine(a, b, c); + }} +//] +}} +class Customer2 +{{ + int a, b, c; +//[ + // {ServicesVSResources.Over_colon} + public override int GetHashCode() + {{ + var hashCode = 339610899; + hashCode = hashCode * -1521134295 + a.GetHashCode(); + hashCode = hashCode * -1521134295 + b.GetHashCode(); + hashCode = hashCode * -1521134295 + c.GetHashCode(); + return hashCode; + }} +//] +}} "; private static readonly string s_preferLocalFunctionOverAnonymousFunction = $@" @@ -1617,6 +1649,7 @@ internal StyleViewModel(OptionStore optionStore, IServiceProvider serviceProvide AddBracesOptions(optionStore, codeBlockPreferencesGroupTitle); CodeStyleItems.Add(new BooleanCodeStyleOptionViewModel(CodeStyleOptions.PreferAutoProperties, ServicesVSResources.analyzer_Prefer_auto_properties, s_preferAutoProperties, s_preferAutoProperties, this, optionStore, codeBlockPreferencesGroupTitle)); CodeStyleItems.Add(new BooleanCodeStyleOptionViewModel(CSharpCodeStyleOptions.PreferSimpleUsingStatement, ServicesVSResources.Prefer_simple_using_statement, s_preferSimpleUsingStatement, s_preferSimpleUsingStatement, this, optionStore, codeBlockPreferencesGroupTitle)); + CodeStyleItems.Add(new BooleanCodeStyleOptionViewModel(CodeStyleOptions.PreferSystemHashCode, ServicesVSResources.Prefer_System_HashCode_in_GetHashCode, s_preferSystemHashCode, s_preferSystemHashCode, this, optionStore, codeBlockPreferencesGroupTitle)); AddParenthesesOptions(OptionStore); diff --git a/src/VisualStudio/Core/Def/ServicesVSResources.Designer.cs b/src/VisualStudio/Core/Def/ServicesVSResources.Designer.cs index 807077f0db6..69ca840880e 100644 --- a/src/VisualStudio/Core/Def/ServicesVSResources.Designer.cs +++ b/src/VisualStudio/Core/Def/ServicesVSResources.Designer.cs @@ -2423,6 +2423,15 @@ internal class ServicesVSResources { } } + /// + /// Looks up a localized string similar to Prefer 'System.HashCode' in 'GetHashCode'. + /// + internal static string Prefer_System_HashCode_in_GetHashCode { + get { + return ResourceManager.GetString("Prefer_System_HashCode_in_GetHashCode", resourceCulture); + } + } + /// /// Looks up a localized string similar to prefer throwing properties. /// @@ -2717,6 +2726,15 @@ internal class ServicesVSResources { } } + /// + /// Looks up a localized string similar to Requires 'System.HashCode' be present in project. + /// + internal static string Requires_System_HashCode_be_present_in_project { + get { + return ResourceManager.GetString("Requires_System_HashCode_be_present_in_project", resourceCulture); + } + } + /// /// Looks up a localized string similar to Reset Visual Studio default keymapping. /// diff --git a/src/VisualStudio/Core/Def/ServicesVSResources.resx b/src/VisualStudio/Core/Def/ServicesVSResources.resx index b5a0455254e..06e190d5e4c 100644 --- a/src/VisualStudio/Core/Def/ServicesVSResources.resx +++ b/src/VisualStudio/Core/Def/ServicesVSResources.resx @@ -1323,4 +1323,10 @@ I agree to all of the foregoing: Updating severity + + Prefer 'System.HashCode' in 'GetHashCode' + + + Requires 'System.HashCode' be present in project + \ No newline at end of file diff --git a/src/VisualStudio/Core/Def/xlf/ServicesVSResources.cs.xlf b/src/VisualStudio/Core/Def/xlf/ServicesVSResources.cs.xlf index 1aad8ad5f47..667d906e4d9 100644 --- a/src/VisualStudio/Core/Def/xlf/ServicesVSResources.cs.xlf +++ b/src/VisualStudio/Core/Def/xlf/ServicesVSResources.cs.xlf @@ -352,6 +352,11 @@ Pozastaveno (počet úloh ve frontě: {0}) + + Prefer 'System.HashCode' in 'GetHashCode' + Prefer 'System.HashCode' in 'GetHashCode' + + Prefer compound assignments Preferovat složená přiřazení @@ -402,6 +407,11 @@ Nahlásit neplatné regulární výrazy + + Requires 'System.HashCode' be present in project + Requires 'System.HashCode' be present in project + + Reset Visual Studio default keymapping Obnovit výchozí mapování klávesnice sady Visual Studio diff --git a/src/VisualStudio/Core/Def/xlf/ServicesVSResources.de.xlf b/src/VisualStudio/Core/Def/xlf/ServicesVSResources.de.xlf index 94c634f6891..e551580b0d0 100644 --- a/src/VisualStudio/Core/Def/xlf/ServicesVSResources.de.xlf +++ b/src/VisualStudio/Core/Def/xlf/ServicesVSResources.de.xlf @@ -352,6 +352,11 @@ Angehalten ({0} Tasks in der Warteschlange) + + Prefer 'System.HashCode' in 'GetHashCode' + Prefer 'System.HashCode' in 'GetHashCode' + + Prefer compound assignments Zusammengesetzte Zuweisungen bevorzugen @@ -402,6 +407,11 @@ Ungültige reguläre Ausdrücke melden + + Requires 'System.HashCode' be present in project + Requires 'System.HashCode' be present in project + + Reset Visual Studio default keymapping Visual Studio-Standardtastenzuordnung zurücksetzen diff --git a/src/VisualStudio/Core/Def/xlf/ServicesVSResources.es.xlf b/src/VisualStudio/Core/Def/xlf/ServicesVSResources.es.xlf index 7419a61a7ba..24fe732b5f5 100644 --- a/src/VisualStudio/Core/Def/xlf/ServicesVSResources.es.xlf +++ b/src/VisualStudio/Core/Def/xlf/ServicesVSResources.es.xlf @@ -352,6 +352,11 @@ En pausa ({0} tareas en cola) + + Prefer 'System.HashCode' in 'GetHashCode' + Prefer 'System.HashCode' in 'GetHashCode' + + Prefer compound assignments Preferir asignaciones compuestas @@ -402,6 +407,11 @@ Notificar expresiones regulares no válidas + + Requires 'System.HashCode' be present in project + Requires 'System.HashCode' be present in project + + Reset Visual Studio default keymapping Restablecer asignaciones de teclado predeterminadas de Visual Studio diff --git a/src/VisualStudio/Core/Def/xlf/ServicesVSResources.fr.xlf b/src/VisualStudio/Core/Def/xlf/ServicesVSResources.fr.xlf index 06156969581..af4fef5a840 100644 --- a/src/VisualStudio/Core/Def/xlf/ServicesVSResources.fr.xlf +++ b/src/VisualStudio/Core/Def/xlf/ServicesVSResources.fr.xlf @@ -352,6 +352,11 @@ Suspendu ({0} tâches en file d'attente) + + Prefer 'System.HashCode' in 'GetHashCode' + Prefer 'System.HashCode' in 'GetHashCode' + + Prefer compound assignments Préférer les affectations composées @@ -402,6 +407,11 @@ Signaler les expressions régulières non valides + + Requires 'System.HashCode' be present in project + Requires 'System.HashCode' be present in project + + Reset Visual Studio default keymapping Réinitialiser la configuration du clavier par défaut de Visual Studio diff --git a/src/VisualStudio/Core/Def/xlf/ServicesVSResources.it.xlf b/src/VisualStudio/Core/Def/xlf/ServicesVSResources.it.xlf index 75c9a00d798..2d4072566ab 100644 --- a/src/VisualStudio/Core/Def/xlf/ServicesVSResources.it.xlf +++ b/src/VisualStudio/Core/Def/xlf/ServicesVSResources.it.xlf @@ -352,6 +352,11 @@ Sospeso ({0} attività in coda) + + Prefer 'System.HashCode' in 'GetHashCode' + Prefer 'System.HashCode' in 'GetHashCode' + + Prefer compound assignments Preferisci assegnazioni composte @@ -402,6 +407,11 @@ Segnala espressioni regolari non valide + + Requires 'System.HashCode' be present in project + Requires 'System.HashCode' be present in project + + Reset Visual Studio default keymapping Reimposta il mapping dei tasti predefinito di Visual Studio diff --git a/src/VisualStudio/Core/Def/xlf/ServicesVSResources.ja.xlf b/src/VisualStudio/Core/Def/xlf/ServicesVSResources.ja.xlf index cf2cfc89f20..121437cd50e 100644 --- a/src/VisualStudio/Core/Def/xlf/ServicesVSResources.ja.xlf +++ b/src/VisualStudio/Core/Def/xlf/ServicesVSResources.ja.xlf @@ -352,6 +352,11 @@ 一時停止中 ({0} 個のタスクがキューにあります) + + Prefer 'System.HashCode' in 'GetHashCode' + Prefer 'System.HashCode' in 'GetHashCode' + + Prefer compound assignments 複合割り当てを優先 @@ -402,6 +407,11 @@ 無効な正規表現を報告 + + Requires 'System.HashCode' be present in project + Requires 'System.HashCode' be present in project + + Reset Visual Studio default keymapping Visual Studio の既定のキーマップをリセットします diff --git a/src/VisualStudio/Core/Def/xlf/ServicesVSResources.ko.xlf b/src/VisualStudio/Core/Def/xlf/ServicesVSResources.ko.xlf index bad968be992..e4de9a269a1 100644 --- a/src/VisualStudio/Core/Def/xlf/ServicesVSResources.ko.xlf +++ b/src/VisualStudio/Core/Def/xlf/ServicesVSResources.ko.xlf @@ -352,6 +352,11 @@ 일시 중지됨(큐의 {0}개 작업) + + Prefer 'System.HashCode' in 'GetHashCode' + Prefer 'System.HashCode' in 'GetHashCode' + + Prefer compound assignments 복합 대입 선호 @@ -402,6 +407,11 @@ 잘못된 정규식 보고 + + Requires 'System.HashCode' be present in project + Requires 'System.HashCode' be present in project + + Reset Visual Studio default keymapping Visual Studio 기본 키 매핑을 다시 설정 diff --git a/src/VisualStudio/Core/Def/xlf/ServicesVSResources.pl.xlf b/src/VisualStudio/Core/Def/xlf/ServicesVSResources.pl.xlf index 280827504fb..46e60275d24 100644 --- a/src/VisualStudio/Core/Def/xlf/ServicesVSResources.pl.xlf +++ b/src/VisualStudio/Core/Def/xlf/ServicesVSResources.pl.xlf @@ -352,6 +352,11 @@ Wstrzymano (zadania w kolejce: {0}) + + Prefer 'System.HashCode' in 'GetHashCode' + Prefer 'System.HashCode' in 'GetHashCode' + + Prefer compound assignments Preferuj przypisania złożone @@ -402,6 +407,11 @@ Raportuj nieprawidłowe wyrażenia regularne + + Requires 'System.HashCode' be present in project + Requires 'System.HashCode' be present in project + + Reset Visual Studio default keymapping Zresetuj domyślne mapowanie klawiszy programu Visual Studio diff --git a/src/VisualStudio/Core/Def/xlf/ServicesVSResources.pt-BR.xlf b/src/VisualStudio/Core/Def/xlf/ServicesVSResources.pt-BR.xlf index 50f9d4dbe04..66571967c8c 100644 --- a/src/VisualStudio/Core/Def/xlf/ServicesVSResources.pt-BR.xlf +++ b/src/VisualStudio/Core/Def/xlf/ServicesVSResources.pt-BR.xlf @@ -352,6 +352,11 @@ Em pausa ({0} tarefas na fila) + + Prefer 'System.HashCode' in 'GetHashCode' + Prefer 'System.HashCode' in 'GetHashCode' + + Prefer compound assignments Preferir atribuições de compostos @@ -402,6 +407,11 @@ Relatar expressões regulares inválidas + + Requires 'System.HashCode' be present in project + Requires 'System.HashCode' be present in project + + Reset Visual Studio default keymapping Redefinir mapeamento de teclas padrão do Visual Studio diff --git a/src/VisualStudio/Core/Def/xlf/ServicesVSResources.ru.xlf b/src/VisualStudio/Core/Def/xlf/ServicesVSResources.ru.xlf index acf8bd4430a..aca96f297db 100644 --- a/src/VisualStudio/Core/Def/xlf/ServicesVSResources.ru.xlf +++ b/src/VisualStudio/Core/Def/xlf/ServicesVSResources.ru.xlf @@ -352,6 +352,11 @@ Приостановлено (задач в очереди: {0}) + + Prefer 'System.HashCode' in 'GetHashCode' + Prefer 'System.HashCode' in 'GetHashCode' + + Prefer compound assignments Предпочитать составные присваивания @@ -402,6 +407,11 @@ Сообщать о недопустимых регулярных выражениях + + Requires 'System.HashCode' be present in project + Requires 'System.HashCode' be present in project + + Reset Visual Studio default keymapping Сброс схемы назначения клавиш Visual Studio по умолчанию diff --git a/src/VisualStudio/Core/Def/xlf/ServicesVSResources.tr.xlf b/src/VisualStudio/Core/Def/xlf/ServicesVSResources.tr.xlf index 88494e7d632..4e56131ab93 100644 --- a/src/VisualStudio/Core/Def/xlf/ServicesVSResources.tr.xlf +++ b/src/VisualStudio/Core/Def/xlf/ServicesVSResources.tr.xlf @@ -352,6 +352,11 @@ Duraklatıldı (kuyrukta {0} görev var) + + Prefer 'System.HashCode' in 'GetHashCode' + Prefer 'System.HashCode' in 'GetHashCode' + + Prefer compound assignments Bileşik atamaları tercih et @@ -402,6 +407,11 @@ Geçersiz normal ifadeleri bildir + + Requires 'System.HashCode' be present in project + Requires 'System.HashCode' be present in project + + Reset Visual Studio default keymapping Visual Studio varsayılan tuş eşlemesine sıfırla diff --git a/src/VisualStudio/Core/Def/xlf/ServicesVSResources.zh-Hans.xlf b/src/VisualStudio/Core/Def/xlf/ServicesVSResources.zh-Hans.xlf index 27c0c4248f3..634b7bc98f6 100644 --- a/src/VisualStudio/Core/Def/xlf/ServicesVSResources.zh-Hans.xlf +++ b/src/VisualStudio/Core/Def/xlf/ServicesVSResources.zh-Hans.xlf @@ -352,6 +352,11 @@ 已暂停(队列中有 {0} 个任务) + + Prefer 'System.HashCode' in 'GetHashCode' + Prefer 'System.HashCode' in 'GetHashCode' + + Prefer compound assignments 首选复合赋值 @@ -402,6 +407,11 @@ 报告无效的正规表达式 + + Requires 'System.HashCode' be present in project + Requires 'System.HashCode' be present in project + + Reset Visual Studio default keymapping 重置 Visual Studio 默认项映射 diff --git a/src/VisualStudio/Core/Def/xlf/ServicesVSResources.zh-Hant.xlf b/src/VisualStudio/Core/Def/xlf/ServicesVSResources.zh-Hant.xlf index 2bf4cbefc33..ebda7bba1e2 100644 --- a/src/VisualStudio/Core/Def/xlf/ServicesVSResources.zh-Hant.xlf +++ b/src/VisualStudio/Core/Def/xlf/ServicesVSResources.zh-Hant.xlf @@ -352,6 +352,11 @@ 已暫停 (佇列中的 {0} 工作) + + Prefer 'System.HashCode' in 'GetHashCode' + Prefer 'System.HashCode' in 'GetHashCode' + + Prefer compound assignments 優先使用複合指派 @@ -402,6 +407,11 @@ 回報無效的規則運算式 + + Requires 'System.HashCode' be present in project + Requires 'System.HashCode' be present in project + + Reset Visual Studio default keymapping 重設 Visual Studio 預設按鍵對應 diff --git a/src/VisualStudio/VisualBasic/Impl/Options/StyleViewModel.vb b/src/VisualStudio/VisualBasic/Impl/Options/StyleViewModel.vb index 953352b83ad..8d05870789f 100644 --- a/src/VisualStudio/VisualBasic/Impl/Options/StyleViewModel.vb +++ b/src/VisualStudio/VisualBasic/Impl/Options/StyleViewModel.vb @@ -349,6 +349,34 @@ Class Customer2 End Property //] End Class +" + + Private Shared ReadOnly s_preferSystemHashCode As String = $" +Imports System + +Class Customer1 + Dim a, b, c As Integer +//[ + ' {ServicesVSResources.Prefer_colon} + // {ServicesVSResources.Requires_System_HashCode_be_present_in_project} + Public Overrides Function GetHashCodeAsInteger() + Return System.HashCode.Combine(a, b, c) + End Function +//] +End Class +Class Customer2 + Dim a, b, c As Integer +//[ + ' {ServicesVSResources.Over_colon} + Public Overrides Function GetHashCodeAsInteger() + Dim hashCode = 339610899 + hashCode = hashCode * -1521134295 + a.GetHashCode() + hashCode = hashCode * -1521134295 + b.GetHashCode() + hashCode = hashCode * -1521134295 + c.GetHashCode() + return hashCode + End Function +//] +End Class " Private Shared ReadOnly s_preferIsNothingCheckOverReferenceEquals As String = $" @@ -657,6 +685,7 @@ End Class ' Code block Me.CodeStyleItems.Add(New BooleanCodeStyleOptionViewModel(CodeStyleOptions.PreferAutoProperties, ServicesVSResources.analyzer_Prefer_auto_properties, s_preferAutoProperties, s_preferAutoProperties, Me, optionStore, codeBlockPreferencesGroupTitle)) + Me.CodeStyleItems.Add(New BooleanCodeStyleOptionViewModel(CodeStyleOptions.PreferSystemHashCode, ServicesVSResources.Prefer_System_HashCode_in_GetHashCode, s_preferSystemHashCode, s_preferSystemHashCode, Me, optionStore, codeBlockPreferencesGroupTitle)) ' expression preferences Me.CodeStyleItems.Add(New BooleanCodeStyleOptionViewModel(CodeStyleOptions.PreferObjectInitializer, ServicesVSResources.Prefer_object_initializer, s_preferObjectInitializer, s_preferObjectInitializer, Me, optionStore, expressionPreferencesGroupTitle)) diff --git a/src/Workspaces/Core/Portable/CodeStyle/CodeStyleOptions.cs b/src/Workspaces/Core/Portable/CodeStyle/CodeStyleOptions.cs index cf1ef41c07e..39a47704dd2 100644 --- a/src/Workspaces/Core/Portable/CodeStyle/CodeStyleOptions.cs +++ b/src/Workspaces/Core/Portable/CodeStyle/CodeStyleOptions.cs @@ -358,11 +358,12 @@ private static string GetAccessibilityModifiersRequiredEditorConfigString(CodeSt KeyValuePairUtil.Create("all", UnusedParametersPreference.AllMethods), }); - internal static readonly PerLanguageOption> PreferSystemHashCode = new PerLanguageOption>( - nameof(CodeStyleOptions), + internal static readonly PerLanguageOption> PreferSystemHashCode = CreateOption( + CodeStyleOptionGroups.ExpressionLevelPreferences, nameof(PreferSystemHashCode), defaultValue: TrueWithSuggestionEnforcement, storageLocations: new OptionStorageLocation[]{ + EditorConfigStorageLocation.ForBoolCodeStyleOption("dotnet_prefer_system_hashcode"), new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.PreferSystemHashCode") }); static CodeStyleOptions() -- GitLab