diff --git a/src/VisualStudio/CSharp/Impl/Options/Formatting/StyleViewModel.cs b/src/VisualStudio/CSharp/Impl/Options/Formatting/StyleViewModel.cs
index b58affd9b3a8ff2fb4c34eed0d5dfc86cb268ebd..3dcacc8768e442019c416f3d17d8a3eefb9e6606 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 807077f0db6024604f4f88aecee38442a51e3b8d..69ca840880e3110f2dac79f764d7f66f755b4f41 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 b5a0455254e6ef4d387948d3c42b140b89afe059..06e190d5e4c97cbbedcbdbf03d8330a0a02e6d6b 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 1aad8ad5f47492159f9884acd049934918d59ca2..667d906e4d9264451554a66f6242f674fa35036f 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 94c634f689147ccb9023c4379dae68f44e8fba75..e551580b0d064b581c3a7a1784271767012a9eef 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 7419a61a7ba5f882a9a3346664b606fc6e9828bc..24fe732b5f58a52ac4dd05867b94da0f7ac998fe 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 06156969581ef4620d71b6bcf9a171b391da70e0..af4fef5a840987b8a353a3d03282ff7c4030023b 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 75c9a00d7980fe36a7542e440ad2dde14b18a167..2d4072566aba720fa9f13df43795f4b68e9f71f7 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 cf2cfc89f2046f68a6868850732b43acf202364c..121437cd50e28676c102c06dc4ab8ab41419527e 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 bad968be992e965965046009b48883f1c9ea11da..e4de9a269a1e1ae49ce91fbd0052b89ed8cf3a75 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 280827504fb6d82350e1fae5920d45f5ded8bd7b..46e60275d2447c86bd22d8e9ec7ff85c6e262cd4 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 50f9d4dbe043de371971ad8c67a1349cca7c6aea..66571967c8cd4952ab29c550f1a5d7ab5a059d91 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 acf8bd4430ac5f6a770ff04e118a402ea2bdd9d5..aca96f297db4882ea40d05efa83442348bccf5b1 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 88494e7d632b46297e5c4983812b74f24c892fbc..4e56131ab9341950901856ca974604c25afe6ac3 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 27c0c4248f35b3993b3bcd452dc356fc360a27d9..634b7bc98f618a47b655143640f837368c70214b 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 2bf4cbefc33e638b0fcc97dc51412e9e4b1c3e5f..ebda7bba1e21424fd5dcb96034b22479235875b1 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 953352b83ad4cf67c70d0ab95c672f06d4d0f518..8d05870789f97ca1ccb00afa92b8ea06210d131c 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 cf1ef41c07e5b3459f7cd9a0226804742b9efc2d..39a47704dd20c6161facfc34f7d1591051f798bc 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()