diff --git a/ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/CreateFieldAction.cs b/ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/CreateFieldAction.cs index 050b3c4de6..2956fe2eae 100644 --- a/ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/CreateFieldAction.cs +++ b/ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/CreateFieldAction.cs @@ -113,13 +113,20 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring if (index < 0) yield break; - var targetResult = resolver.Resolve(invoke.Target); - if (targetResult is MethodGroupResolveResult) { - foreach (var method in ((MethodGroupResolveResult)targetResult).Methods) { + var targetResult = resolver.Resolve(invoke.Target) as MethodGroupResolveResult; + if (targetResult != null) { + foreach (var method in targetResult.Methods) { if (index < method.Parameters.Count) { 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; + } + } + } } } diff --git a/ICSharpCode.NRefactory.Tests/CSharp/CodeActions/CreateLocalVariableTests.cs b/ICSharpCode.NRefactory.Tests/CSharp/CodeActions/CreateLocalVariableTests.cs index b928a304e4..b26c6c09bc 100644 --- a/ICSharpCode.NRefactory.Tests/CSharp/CodeActions/CreateLocalVariableTests.cs +++ b/ICSharpCode.NRefactory.Tests/CSharp/CodeActions/CreateLocalVariableTests.cs @@ -236,5 +236,48 @@ namespace ICSharpCode.NRefactory.CSharp.CodeActions }"); } + [Test] + public void TestExtensionMethod() + { + Test(@"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(@"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); + } +}"); + } + } } \ No newline at end of file