Extension method information from Roslyn -
i trying using roslyn extract various method call information give source file. elaborate - want find method invocations happen inside input file.
one problem hitting extension methods. consider linq
method aggregate
, sum
etc. how can figure out invocationexpressionsyntax
method being invoked extension method , not simple member method of class.
the source file input can expected compile - meaning getdiagnostics()
not have errors.
---- code property mentioned @kevin in answer ----
var methodinfo = model.getsymbolinfo(invocation); if (methodinfo.symbol != null) { var msymbol = (imethodsymbol)methodinfo.symbol; if (msymbol.reducedfrom != null) { // extension method ! } }
you can find actual static extension method instance invocation of extension method using imethodsymbol.reducedfrom
property.
Comments
Post a Comment