roslyn-analyzers icon indicating copy to clipboard operation
roslyn-analyzers copied to clipboard

Analyze called Methods

Open p3t3rix opened this issue 5 years ago • 3 comments

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.

p3t3rix avatar Apr 26 '19 13:04 p3t3rix

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.

angularsen avatar Apr 28 '19 10:04 angularsen

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 ?

p3t3rix avatar Jul 02 '19 12:07 p3t3rix

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.

angularsen avatar Jul 02 '19 12:07 angularsen