diff --git a/src/Features/CSharp/Portable/UseLocalFunction/CSharpUseLocalFunctionDiagnosticAnalyzer.cs b/src/Features/CSharp/Portable/UseLocalFunction/CSharpUseLocalFunctionDiagnosticAnalyzer.cs index de3892c20c4739798345b6956535604a755292e7..1a6c585ac7f33537a229e2f42c1a1275e063fd5c 100644 --- a/src/Features/CSharp/Portable/UseLocalFunction/CSharpUseLocalFunctionDiagnosticAnalyzer.cs +++ b/src/Features/CSharp/Portable/UseLocalFunction/CSharpUseLocalFunctionDiagnosticAnalyzer.cs @@ -82,7 +82,6 @@ private void SyntaxNodeAction(SyntaxNodeAnalysisContext syntaxContext) return; } - if (localDeclaration.Declaration.Variables.Count != 1) { return; diff --git a/src/VisualStudio/CSharp/Impl/Options/Formatting/StyleViewModel.cs b/src/VisualStudio/CSharp/Impl/Options/Formatting/StyleViewModel.cs index e52f086cd0d96cf8baf37dc19386dc753b92c800..81677a4e3236b6a9d14e16e18ca53032f1d84f93 100644 --- a/src/VisualStudio/CSharp/Impl/Options/Formatting/StyleViewModel.cs +++ b/src/VisualStudio/CSharp/Impl/Options/Formatting/StyleViewModel.cs @@ -523,6 +523,31 @@ public int GetAge() //] }} }} +"; + + private static readonly string s_preferLocalFunctionOverAnonymousFunction = $@" +using System; + +class Customer +{{ + public Customer(string value) + {{ +//[ + // {ServicesVSResources.Prefer_colon} + int fibonacci(int n) + {{ + return n <= 1 ? 1 : fibonacci(n - 1) + fibonacci(n - 2); + }} + + // {ServicesVSResources.Over_colon} + Func fibonacci = null; + fibonacci = (int n) => + {{ + return n <= 1 ? 1 : fibonacci(n - 1) + fibonacci(n - 2); + }}; +//] + }} +}} "; private const string s_preferExpressionBodyForMethods = @" @@ -747,6 +772,7 @@ internal StyleViewModel(OptionSet optionSet, IServiceProvider serviceProvider) : CodeStyleItems.Add(new BooleanCodeStyleOptionViewModel(CSharpCodeStyleOptions.PreferSimpleDefaultExpression, ServicesVSResources.Prefer_simple_default_expression, s_preferSimpleDefaultExpression, s_preferSimpleDefaultExpression, this, optionSet, expressionPreferencesGroupTitle)); CodeStyleItems.Add(new BooleanCodeStyleOptionViewModel(CSharpCodeStyleOptions.PreferInferredTupleNames, ServicesVSResources.Prefer_inferred_tuple_names, s_preferInferredTupleName, s_preferInferredTupleName, this, optionSet, expressionPreferencesGroupTitle)); CodeStyleItems.Add(new BooleanCodeStyleOptionViewModel(CSharpCodeStyleOptions.PreferInferredAnonymousTypeMemberNames, ServicesVSResources.Prefer_inferred_anonymous_type_member_names, s_preferInferredAnonymousTypeMemberName, s_preferInferredAnonymousTypeMemberName, this, optionSet, expressionPreferencesGroupTitle)); + CodeStyleItems.Add(new BooleanCodeStyleOptionViewModel(CSharpCodeStyleOptions.PreferLocalOverAnonymousFunction, ServicesVSResources.Prefer_local_function_over_anonymous_function, s_preferLocalFunctionOverAnonymousFunction, s_preferLocalFunctionOverAnonymousFunction, this, optionSet, expressionPreferencesGroupTitle)); AddExpressionBodyOptions(optionSet, expressionPreferencesGroupTitle); diff --git a/src/VisualStudio/Core/Def/ServicesVSResources.Designer.cs b/src/VisualStudio/Core/Def/ServicesVSResources.Designer.cs index 1419c2e4a553c0b8dbf2b84de6c04b856bd02f50..661400367b1a3cbe57875652015456acc2db8fc1 100644 --- a/src/VisualStudio/Core/Def/ServicesVSResources.Designer.cs +++ b/src/VisualStudio/Core/Def/ServicesVSResources.Designer.cs @@ -1639,6 +1639,15 @@ internal class ServicesVSResources { } } + /// + /// Looks up a localized string similar to Prefere local function over anonymous function. + /// + internal static string Prefer_local_function_over_anonymous_function { + get { + return ResourceManager.GetString("Prefer_local_function_over_anonymous_function", resourceCulture); + } + } + /// /// Looks up a localized string similar to Prefer null propagation. /// diff --git a/src/VisualStudio/Core/Def/ServicesVSResources.resx b/src/VisualStudio/Core/Def/ServicesVSResources.resx index 1b4582288aee1485f331d8006f508b8226da1903..cb67db1e584ce6ccc8f57df252a2cf45e97d146c 100644 --- a/src/VisualStudio/Core/Def/ServicesVSResources.resx +++ b/src/VisualStudio/Core/Def/ServicesVSResources.resx @@ -959,4 +959,7 @@ Additional information: {1} Changes are not allowed while code is running. + + Prefere local function over anonymous function + \ No newline at end of file