0

I'm working on a VB.NET codebase that uses legacy naming conventions vaguely similar to Hungarian Notiation, for instance:

  • A member string Test would be mstrTest
  • A function-scope int Test would be lintTest
  • A parameter Object Test would be pobjTest

In order to verify that variables are being named correctly, and to work out a solution to each non-conforming variable name, I need to find any instance of variables in the codebase, along with their scope and type.

I've done some tests using regexes to look for Functions and Subs, but instances of class member variables (for instance) would be difficult to do in this way, not to mention that parsing code with Regexes feels incorrect.

Is there a way (in C#) that I could create some kind of structured hierarchy from the codebase without having to start from scratch, or a better way to achieve this tack in general?

Apologies if my explanation is wrong/vague, I've not attempted to parse a language before.

3
  • 2
    Hungarian notation was considered very bad practice even in the days of VB6. What you are asking require code analysis. Regex expressions aren't enough. You can use tools like Resharper to find and even rename the variables using its SDK although there may be plugins that already do what you want. In .NET vNext the Roslyn compiler will allow you to do this out-of-the-box. Perhaps you can try VS2015 CTP 6 to create a quick-and-dirty utility if you don't want to use Resharper Commented Mar 6, 2015 at 11:34
  • I'm definitely aware that the notation is terrible :) When you say this: "In .NET vNext the Roslyn compiler will allow you to do this out-of-the-box" Looking up vNext, it looks like it's an ASP.NET feature, do you have a link with more information about variable naming? I've thought about using Roslyn as I think that'd be the best way, I'll see if it will allow me to do this kind of thing. Commented Mar 6, 2015 at 11:40
  • 1
    No, it isn't. It's the compiler used by both VB.NET and C#. You can start from Roslyn's GitHub repository, it contains several samples that show how to write analyzers, refactorings etc, as well as documentation on syntax and semantic analysis. Also check Kathleen Dollard's RoslynDOM library which simplifies coding significantly Commented Mar 6, 2015 at 11:51

1 Answer 1

2

Hungarian notation was considered very bad practice even in the days of VB6. What you are asking require code analysis.

Regex expressions aren't enough. You can use tools like Resharper to find and even rename the variables using its SDK although there may be plugins that already do what you want. In .NET vNext the Roslyn compiler will allow you to do this out-of-the-box. Perhaps you can try VS2015 CTP 6 to create a quick-and-dirty utility if you don't want to use Resharper.

You can start from Roslyn's GitHub repository, it contains several samples that show how to write analyzers, refactorings etc, as well as documentation on syntax and semantic analysis. Also check Kathleen Dollard's RoslynDOM library which simplifies coding significantly

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.