[英]How to find system.Type of parameter of MethodDeclaractionSyntax with roslyn?
I get IL of methods with extension method:我用扩展方法得到方法的 IL:
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[].所以我需要使用下面需要 Type[] 的方法。
//this will replace in above method
m.GetMethod("NameOfMethod",ArrayTypeOfParameter);
But how can I get Type from TypeSyntax ?但是如何从 TypeSyntax 获取 Type ?
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.从您的ParameterSyntax
p 中,使用SemanticModel.GetDeclaredSymbol
获取IParameterSymbol
,然后查看其Type
以获取您感兴趣的ITypeSymbol
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.