提交 ece8f8d8 编写于 作者: S Sam Harwell

Fix Extract Method operations within an event accessor

Fixes #17474
上级 05480ee4
......@@ -10079,6 +10079,47 @@ private async Task<int> NewMethod(S s)
await TestExtractMethodAsync(code, expected, dontPutOutOrRefOnStruct: true);
}
[Theory]
[InlineData("add", "remove")]
[InlineData("remove", "add")]
[WorkItem(17474, "https://github.com/dotnet/roslyn/issues/17474")]
[Trait(Traits.Feature, Traits.Features.ExtractMethod)]
public async Task TestExtractMethodEventAccessorUnresolvedName(string testedAccessor, string untestedAccessor)
{
// This code intentionally omits a 'using System;'
var code =
$@"namespace ClassLibrary9
{{
public class Class
{{
public event EventHandler Event
{{
{testedAccessor} {{ [|throw new NotImplementedException();|] }}
{untestedAccessor} {{ throw new NotImplementedException(); }}
}}
}}
}}";
var expected =
$@"namespace ClassLibrary9
{{
public class Class
{{
public event EventHandler Event
{{
{testedAccessor} {{ NewMethod(); }}
{untestedAccessor} {{ throw new NotImplementedException(); }}
}}
private static void NewMethod()
{{
throw new NotImplementedException();
}}
}}
}}";
await TestExtractMethodAsync(code, expected);
}
[Fact, Trait(Traits.Feature, Traits.Features.ExtractMethod)]
public async Task ExtractMethod_Argument1()
{
......
......@@ -71,13 +71,23 @@ public override ITypeSymbol GetContainingScopeType()
switch (node)
{
case AccessorDeclarationSyntax access:
// property case
// property or event case
if (access.Parent == null || access.Parent.Parent == null)
{
return null;
}
return ((IPropertySymbol)semanticModel.GetDeclaredSymbol(access.Parent.Parent)).Type;
switch (semanticModel.GetDeclaredSymbol(access.Parent.Parent))
{
case IPropertySymbol propertySymbol:
return propertySymbol.Type;
case IEventSymbol eventSymbol:
return eventSymbol.Type;
default:
return null;
}
case MethodDeclarationSyntax method:
return semanticModel.GetDeclaredSymbol(method).ReturnType;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册