Is it possible to create a search pattern in the pattern catalog of Resharper to find all constructors with more than 3 parameters?
If so, how?
My problem is that I don't know how to tell Resharper that only constructor definitions should match.
As far as I know the patterns in Resharper can only be matched within a method. So you couldn't match the constructor declaration.
I just tried the following pattern though:
new $type$($args$)
Where type is a placeholder for a type (who would have guessed?) and args for at least 3 arguments. This indeed finds all uses of at least 3 arguments constructors, but it wouldn't find constructors that are not used, and most importantly, it would find this:
public class MyClass : MyAbstractClass
{
public MyClass(int foo1, int foo2) : base(foo1, foo2, 0)
{
// ...
}
}
So maybe if you think you're going to have these cases, instead of using Resharper patterns you should try to use regex Find. It can be hard because come to think of it C# syntax is quite complex, but you could get to something...
Edit: I adapted a visual studio regex search for a constructor declaration, recognizes new lines and at least arguments (which can have optional values):
^(:b|\n)*((public|internal|private|protected|static|sealed)(:b|\n)+)+:i(:b|\n)*\((:b|\n)*:i(:b|\n)+:i(:b|\n)*(|\=(:b|\n)*:a*(:b|\n)*)(,(:b|\n)*:i(:b|\n)+:i(:b|\n)*(|\=(:b|\n)*:a*(:b|\n)*))^2(,(:b|\n)*:i(:b|\n)+:i(:b|\n)*(|\=(:b|\n)*:a*(:b|\n)*))*\)
it's ugly mainly because the VS custom regex doesn't have any translation for the standard \w, {2,} and ?.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With