RegexPatternAttribute in an attribute argument
Hello,
I am using Specflow for my unit tests. It uses attributes that contain regular expressions like:
[Given(@"the method returns (\d+)")]
I can mark each attribute usage as regular expression, but I did not succeed with marking the attribute with the RegexPatternAttribute. Resharper s not highlighting regular expressions in the string.
public class GivenAttribute : StepDefinitionBaseAttribute
{
public GivenAttribute([RegexPattern] string regex) : base(regex, StepDefinitionType.Given)
{
}
}
Is it possible to mark attribute arguments with JetBrains annotations?
Greetings
Peter
Please sign in to leave a comment.
Hello Peter
How did you add JetBrains.Annotations to the project - as a code file or as a nuget package to references?
Thanks!
Hello Alexander,
thanks for your response.
I used a local code file, copied from the settings dialog. I'm using Resharper 2017.1.2 with Visual Studio 2017 (15.2 / 26430.6).
I played around some more and tried to install the nuget package. The curious thing is, that there was a moment, when I got highlighted regex strings. But only in some files. But then I restarted Visual Studio and now I'm not seeing it any more.
You can checkout my github branch at https://github.com/Peter-B-/SpecFlow/tree/AddResharperRegexAnnotations, if you want to see if you can reproduce it.
Thanks already for your help.
Peter
Peter,
To get it to work with a local code file, you need to check a "namespace" checkbox here ReSharper | Options | Code Inspection | Code Annotations page.
Thanks!
As for the fact that it works only for several files, please specify which files it does not work for.
Thanks!
Hi,
I use the JetBrains.Annotations namespace. So i think that sould work out of the box, shouldn't it?
I have a feeling, that it worked for files where I didn't use "Mark as .Net Regular Expression" before. But, as I said, I cannot reproduce that since I restarted Visual Studio.
Peter,
You are absolutely right, it should work out-of-the-box for JetBrains.Annotations namespace. I filed a new request https://youtrack.jetbrains.com/issue/RSRP-464796 for deeper investigation, since something is definitely wrong with such attribute, it worked for me from time to time and I don't think it is expected result.
My apologies for the inconvenience.
Thanks!
Hi Alexander,
thanks a lot for your prompt support here. It's not a big issue, but would be nice to have.
Greetings
Peter