Browse Source

Handled extension methods in type guessing code.

pull/32/merge
Mike Krüger 13 years ago
parent
commit
54bb967d8a
  1. 13
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/CreateFieldAction.cs
  2. 43
      ICSharpCode.NRefactory.Tests/CSharp/CodeActions/CreateLocalVariableTests.cs

13
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/CreateFieldAction.cs

@ -113,13 +113,20 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
if (index < 0) if (index < 0)
yield break; yield break;
var targetResult = resolver.Resolve(invoke.Target); var targetResult = resolver.Resolve(invoke.Target) as MethodGroupResolveResult;
if (targetResult is MethodGroupResolveResult) { if (targetResult != null) {
foreach (var method in ((MethodGroupResolveResult)targetResult).Methods) { foreach (var method in targetResult.Methods) {
if (index < method.Parameters.Count) { if (index < method.Parameters.Count) {
yield return method.Parameters [index].Type; yield return method.Parameters [index].Type;
} }
} }
foreach (var extMethods in targetResult.GetExtensionMethods ()) {
foreach (var extMethod in extMethods) {
if (index + 1 < extMethod.Parameters.Count) {
yield return extMethod.Parameters [index + 1].Type;
}
}
}
} }
} }

43
ICSharpCode.NRefactory.Tests/CSharp/CodeActions/CreateLocalVariableTests.cs

@ -236,5 +236,48 @@ namespace ICSharpCode.NRefactory.CSharp.CodeActions
}"); }");
} }
[Test]
public void TestExtensionMethod()
{
Test<CreateLocalVariableAction>(@"static class Ext { public static void Foo(this object o, string str) {} }
class Test
{
public static void Main (string[] args)
{
args.Foo($foo);
}
}", @"static class Ext { public static void Foo(this object o, string str) {} }
class Test
{
public static void Main (string[] args)
{
string foo;
args.Foo(foo);
}
}");
}
[Test]
public void TestExtensionMethodStaticInvocation()
{
Test<CreateLocalVariableAction>(@"static class Ext { public static void Foo(this object o, string str) {} }
class Test
{
public static void Main (string[] args)
{
Ext.Foo(args, $foo);
}
}", @"static class Ext { public static void Foo(this object o, string str) {} }
class Test
{
public static void Main (string[] args)
{
string foo;
Ext.Foo(args, foo);
}
}");
}
} }
} }
Loading…
Cancel
Save