RefactoringEssentials
RefactoringEssentials copied to clipboard
RECS0015 leads to infinite recursion
trafficstars
Let's have the following code:
public static class SimpleTextEx
{
public static SimpleText Times(this int number, SimpleText text)
{
return TextEx.Times(number, text); // <-- RECS0015 // If an extension method is called as static method convert it to method syntax
}
}
public static class TextEx
{
public static string Times(this int number, string text)
{
throw new NotImplementedException();
}
}
public class SimpleText
{
public static implicit operator string(SimpleText text)
{
throw new NotImplementedException();
}
public static implicit operator SimpleText(string text)
{
throw new NotImplementedException();
}
}
RE incorrectly suggests to replace the static call with extension call. This however produces the infinite recursion.
Similar situation is following:
public class Foo { }
public static class FooEx
{
public static string GetType(this Foo foo)
{
throw new NotImplementedException();
}
}
class Program
{
static string Bar(Foo foo)
{
return FooEx.GetType(foo); // <-- RECS0015 // If an extension method is called as static method convert it to method syntax
}
}
(Fortunately, this however causes a compilation error.)