How to match methods without a specific category

63 views Asked by At

I need to remove some tests from several classes without some specific category

how do I match than?

in this example i want to remove only the methods 'Bar' and 'BarTwo'

namespace MyNameSpace
{
    /// <summary>
    /// Some Stuff
    /// </summary>
    public class MyClass
    {
        [CategoryA]
        public void Foo()
        {
        }

        public void Bar()
        {
        }

        [CategoryA]
        public void Baz()
        {
        }

        public void BarTwo()
        {
        }
    }
}
1

There are 1 answers

4
karthik manchala On BEST ANSWER

You can use the following to match:

(?<!]\s)public\s+void[^[]+(?=\[|\s*}\s*}$)

And replace with '' (empty string)

See DEMO

Note1 : I assumed all your methods start with public if not you can use the following:

(?<!]\s*)(public|private|protected)\s+void[^[]+(?=\[|\s*}\s*}$)

Note2 : I also assumed that there wont be any [ or ] in your methods.