简体   繁体   中英

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?

I don't think you can make the compiler throw that error for you. You might be able to introduce an extra build step that executes a C# console app that checks (using reflection) what you want.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM