2
我得到IL與擴展方法方法:如何使用roslyn查找MethodDeclaractionSyntax參數的system.Type?
public static byte[] getIL(this Type t,string nameOfMethod)
{
MethodBody mb=t.GetMethods(BindingFalgs...).Where(m=>m.Name ==nameOfMethod).Single();
return mb.GetMethodBody().GetIlAsByteArray();
}
因爲我的解決方案具有過載(同名)的方法我得到異常(有不止一個)。
所以我需要使用下面的方法,需要類型[]。
//this will replace in above method
m.GetMethod("NameOfMethod",ArrayTypeOfParameter);
但是我怎樣才能從TypeSyntax獲得Type?
public override SyntaxNode VisitMethodDeclarationSyntax(MethodDeclarationSyntax m)
{
foreach(ParameterSyntax p in m.ParameterList.Parameters)
{
TypeSyntax t=p.Type;
//how get system.Type here
}
我需要的System.Type發送的getMethod。如何從得到的System.Type ITypeSymbol? – mohsen
你不能 - 反射和羅斯林是不同的世界。您可以使用Type.MetadataName找到解決方法,然後通過反射來找到正確的類型。 –