Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I find all signatures(overloads) of a method in Roslyn in a class or partial class files?

Via Roslyn, C# syntax ,I have IMethodSymbol to clarify my method information,

var symbolMethod = context.SemanticModel.GetSymbolInfo(invocation).Symbol as IMethodSymbol;

if (symbolMethod == null) return;
//-- Here I need to get other signature of the symbolMethod 

Notation: the container class maybe has partial class which includes some signature of this method

like image 759
Ali Sarshogh Avatar asked Feb 05 '16 11:02

Ali Sarshogh


3 Answers

Just do symbolMethod.ContainingType, and from there you can call GetMembers to get all members of the type. You can filter by name or whatever you're looking to get from there.

like image 137
Jason Malinowski Avatar answered Nov 01 '22 11:11

Jason Malinowski


You could look into SemtanticModel.GetMemberGroup:

var overloads = model.GetMemberGroup(invocation.Expression);

It returns a list of overloads of the method

like image 32
ghord Avatar answered Nov 01 '22 09:11

ghord


var symbolMethod = context.SemanticModel.GetSymbolInfo(invocation).Symbol as IMethodSymbol;
//has several signatures
if (symbolMethod.ContainingType.GetMembers().Count(it => it.Name == symbolMethod.Name) > 1) 
like image 34
Ali Sarshogh Avatar answered Nov 01 '22 11:11

Ali Sarshogh