I've extracted all InvocationExpressionSyntax
's from a parsed C# script with results like:
1. System.IO.Directory.GetDirectories(@"c:\").First()
2. Math.Sin(3).ToString()
3. value.Substring(0, 1)
I also have the SemanticModel object and have searched and experimented in various ways to do the following:
- Iterate from the last to the first invocation call and determine which CLR type it belongs to. As an example,
Math.Sin(3).ToString()
should tell me that the method isToString
while the type isDouble
. In the next iteration the method would beSin
and the Type would beMath
. - In order to do the above, I have a hard-coded list of types
List<Type> Allowed
. I now want to extract theCLR Type
of each segment of theInvocationExpressionSyntax
and see if it is included in the whitelist.
The objective is to white-list types and calls to a small subset that end-users can utilize. Example, Math.XXX
is ok, Directory.XXX
is not.
I have searched around and experimented quite a bit but have not figured out how to extract a Type
object against each expression. Expected types of course are MethodInfo
, PropertyInfo
and Class
.
Any pointers would be appreciated.