1

I have a class (constructor) that I need exposed within a business-tier, but it needs careful thought and justification for use (of ANY of its members). I'd like it to generate a compiler warning by default, and establish our team process as recording inline usage justification and a pragma suppress or similar.

Ideally the warning would be custom text, for example:

WARNING: This code circumvents user security filters. If you intended this, please comment here how this code precludes exposure of sensitive data, then follow with #pragma suppress.

Also ideally, the message displays without team members having to install anything into their VS. We use VS 2017

I currently have the code marked [Obsolete], but it's semantically inaccurate and requires wrapping one or more lines with #pragma warning disable 0618 followed by #pragma warning enable 0618. I'd rather encourage individual resolution of each line, similar to the #pragma suppress syntax.

If you suspect a duplicate question, please read this: Note that I've reviewed other "similar" questions. Some seek to mark code as needing review (the accepted answer is this is an inappropriate use of compiler warnings). Some truly represent Obsolete code, so the answer is obvious. Some see complex rules, like "you must also call a sibling method".

shannon
  • 8,664
  • 5
  • 44
  • 74
  • 1
    Please provide information (such as advice or rationale) with downvotes. Thank you. – shannon Aug 04 '17 at 18:22
  • 1
    You may be interested in the answers and related questions of https://stackoverflow.com/questions/154109. Looks like you can solve it with Roslyn – devio Aug 04 '17 at 21:26

1 Answers1

1

I see this as a common problem with places that deal with a large legacy code, but I still have not found the ideal solution for this. What I have done in the past, that has at least worked my teams, was use the code map feature of Visual Studio. Take a look at Map dependencies across your solutions. This code map uses Microsoft's DGML which is XML style document that is designed to create links between objects. If you write a tool or script that parses this document and looks for uses of the constructor in question and run it in a CI build, you can track the usages of it and flag a build/commit when a new use is detected. This way, you don't have to install it on any of the developer's machines and unless you are build admin, you aren't turning off this step.

tj-cappelletti
  • 1,774
  • 12
  • 19