简体   繁体   中英

How to find system.Type of parameter of MethodDeclaractionSyntax with roslyn?

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
 }

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM