Reputation: 1806
I get IL of methods with extension method:
public static byte[] getIL(this Type t,string nameOfMethod)
{
MethodBody mb=t.GetMethods(BindingFalgs...).Where(m=>m.Name ==nameOfMethod ).Single();
return mb.GetMethodBody().GetIlAsByteArray();
}
Because my solution has Overload (with same name) method I got exception(has more than one).
So I need to use below method that need Type[].
//this will replace in above method
m.GetMethod("NameOfMethod",ArrayTypeOfParameter);
But how can I get Type from TypeSyntax ?
public override SyntaxNode VisitMethodDeclarationSyntax(MethodDeclarationSyntax m)
{
foreach(ParameterSyntax p in m.ParameterList.Parameters)
{
TypeSyntax t=p.Type;
//how get system.Type here
}
Upvotes: 3
Views: 587
Reputation: 5836
You're going to need symbols here.
From your ParameterSyntax
p, use SemanticModel.GetDeclaredSymbol
to get the IParameterSymbol
, and then look at its Type
to get the ITypeSymbol
you are interested in.
Upvotes: 3