The codebase I've inherited seems to have a bunch of public variables, and as I come across them I tend to convert them into properties, document them, and format them according to our stylecop rules (it's my own little version of kaizen - eventually the codebase will be clean) but I was just wondering if there is a good search string that I could use in vs to find all of the public variables in the project?
I am not a regex expert but you can use RegEx in VS find window. Just Ctrl+Shift+F to open Find in Files and in Find Options check off Use Regular Expressions.
this should give you something
public [^(){}]*[;]
You can make a regular expression to match all "public variables" and then use it in Find and Replace Window (Ctrl+Shift+F)
You can always use the ClassView (Ctrl+Shift+C) and "Sort by Object Access"
You can use the following RegEx to find them all:
public:b+{{new|static|readonly|volatile|const}:b+}*{:i}:b+{:i}:b+;
The first and second capture are the additional field modifiers besides public. The third capture is the type, the fourth is the field name. Keep in mind the standard doesn't require that the access modifier come before any of the other valid field modifiers, so you may want to prepend {{new|static|readonly|volatile|const}:b+}*
to the beginning for completeness. It isn't really required for most code.
I think it may be difficult to use regex or find and replace for what you want. Seems to me you could create a custom StyleCop rule to find what you want.
You might get some ideas from this blog entry that writes a rule that sorts members by their access level.