Conversation started May 21, 2015 at 9:42.
May 21, 2015 09:42
@JeroenVannevel you've been playing with the analyzer code. I've got a question for you when you have a second. Let's say I have a class that I use internally, but am in turn exposing a slightly altered interface of it to COM Interop. So, for the sake of code reuse, this class needs a particular constructor that should only be used by code in my Rubberduck.SourceControl.Interop namespace.
If I created a custom attribute, like Obsolete only different. Something like InteropOnly say... I should be able to write an analyzer to reflect over the code, look for the attribute and if the namespace isn't Interop, raise a warning about it, right?
I know that sounds very theoretical (because it is), but it seems to be an interesting possible use of a project specific analyzer. Thoughts about it?
Yes, very possible
A few lines of code and you're done
Seems like you think it'd be pretty simple then eh?
I'll tuck that away in an issue somewhere and come back to it when I talk Mug into upgrading to 6.0.
You just register a code inspection on ObjectCreationExpressionSyntax and look at semanticModel.GetSymbolInfo(expression.Type). Now you can retrieve all the attributes using symbol.GetAttributes(). For each attribute, look if its attribute.AttributeClass.MetaDataName is equal to InteropOnlyAttribute. Now all that's left is verifying if you're in the namespace you should be in using expression.AncestorsAndSelf().OfType<NamespaceDeclarationSyntax>().First().Name‌​
Oh dang. That is pretty simple.
I didn't figure it would be hard and I knew you were the guy to ask.
Thanks.
May 21, 2015 09:52
Man, I bet some custom analyzation would be worth it's weight in gold for any OSS project.
I agree. You can basically provide develop-time warnings for any codebase specific quirks you have
3
Set your standards, distribute them along with the rest of the source. Contriubtors know up front if they're meeting the basic style guides.
 
Conversation ended May 21, 2015 at 9:53.