-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug fix extract local function errors C#7 and below #55446
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I started to work on this in #55135 and the proposed solution was to capture or to rename the parameters.
src/EditorFeatures/CSharpTest/CodeActions/ExtractMethod/ExtractLocalFunctionTests.cs
Outdated
Show resolved
Hide resolved
src/EditorFeatures/CSharpTest/CodeActions/ExtractMethod/ExtractLocalFunctionTests.cs
Show resolved
Hide resolved
src/EditorFeatures/CSharpTest/CodeActions/ExtractMethod/ExtractLocalFunctionTests.cs
Show resolved
Hide resolved
@akhera99 If you struggle to find a way to identify a linq range variable: I would suggest adding a property to protected abstract class VariableSymbol
{
public abstract bool CanBeCapturedByLocalFunction { get; }
} This should return false in You can expose protected class VariableInfo
{
/// <summary>
/// Returns true, if the variable could be either passed as a parameter
/// to the new local function or the local function can capture the variable.
/// </summary>
public bool CanBeCapturedByLocalFunction
=> _variableSymbol.CanBeCapturedByLocalFunction;
} |
Thank you for your help. I was trying to avoid looking explicitly at the AnalyzerResult information, but that is definitely the easiest way to handle it. |
Fixes: #55031
Opts to capture variables instead of creating new parameters in language versions below c#8 because they do not support static local functions.