Harry Sarshogh
Harry Sarshogh

Reputation: 2197

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

Upvotes: 5

Views: 1327

Answers (3)

Harry Sarshogh
Harry Sarshogh

Reputation: 2197

var symbolMethod = context.SemanticModel.GetSymbolInfo(invocation).Symbol as IMethodSymbol;
//has several signatures
if (symbolMethod.ContainingType.GetMembers().Count(it => it.Name == symbolMethod.Name) > 1) 

Upvotes: 1

ghord
ghord

Reputation: 13835

You could look into SemtanticModel.GetMemberGroup:

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

It returns a list of overloads of the method

Upvotes: 3

Jason Malinowski
Jason Malinowski

Reputation: 19031

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.

Upvotes: 4

Related Questions