c# 反射获取一个类型取到null

经常用 GetType 获取一个Type

1. 想获取的 Type 在当前执行的 assembly 里面,则可以直接获取

Type myType1 = Type.GetType("System.Int32");

2. 想获取的 Type 不在当前的assembly 里面,直接获取得到 null

Type t = Type.GetType("System.Runtime.InteropServices.RuntimeInformation");
// t == null

必须用 AssemblyQualifiedName 去获取

Type t = Type.GetType("System.Runtime.InteropServices.RuntimeInformation, System.Runtime.InteropServices.RuntimeInformation, Version=4.0.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");

 

posted @ 2020-02-26 11:47  内心澎湃的水晶侠  阅读(740)  评论(0编辑  收藏  举报