Search code examples
c#compilationpostsharpilvisual-studio-2015

Compile Time: How can I check if a datatype (and or value) is being used within a method


At compile time, how can I check if a data type (and or value) is being used within a method.

I'm attempting to build a living architecture that supports plugins.

I want the compiler to throw an error if an event is not being raised within the plugin.

I'm using VS2015 Preview.

Any suggestions?


Solution

  • This kind of validation is possible to implement using PostSharp. It is not trivial but easier than using Mono.Cecil. SyntaxTreeVisitor and ISyntaxReflectionService is a good foundation for implementing the analysis algorithm which has to be invoked from Aspect.CompileTimeValidate.

    Roslyn must be mentioned as well. It allows you to "extend" C# (or VisualBasic) compiler with custom diagnostics and it is very well integrated with VS2015.

    Disclaimer: I'm PostSharp developer.