roslyn-analyzers
roslyn-analyzers copied to clipboard
Analyze called Methods
Hi, i wonder if it would be possible to add/adapt the analyzer to also check called Methods. For Example:
abstract class MapperBase<TSource, TTarget>
{
//AssignAllDeep enable
public abstract TTarget Map(TSource source);
//AssignAllDeep disable
}
So it would not be possible to forget to add the magic comment to the child classes.
Hi, I suppose that is possible. I'm happy to merge it in if you do a pull request and add some tests to validate the behavior. I am not actively maintaining this project, I just created this thing that solved a particular need for me.
I looked into this and as far as i can tell it would require a quite separate functionality, because at the moment all things are done via syntax analysis on the current file. A deep inspection as imagined by me would require semantically analyzing all files for occurrences of the methods, finding out the lines they are in and then call the current analyzing functionality. Do you have a better idea to basically ensure that the mapping does not ignore newly added members ?
I'm rusty on this domain, but I think what you are saying sounds about right. If you need to get an overview of all invocations of certain methods, then you need to approach it slightly differently and use semantic code analysis - which is a different step/API in the Roslyn. I do think you should be able to pull it off though, I think all the pieces and APIs you need exist, but you will have to do some digging. I'm sure you can find examples that work kind of similar to what you need from semantic analysis, I think I saw some back when I was working on this.
My guess, use syntax analysis to map all special comments and identify methods of types, then use semantic analysis to find all invocations of said methods.