Type.GetType("System.Data.DataTable"); 返回 null
解决方法:
Assembly assembly2 = typeof(System.Data.DataTable).Assembly;
Type type2 = assembly2.GetType("System.Data.DataTable");
参考:https://stackoverflow.com/questions/7441003/type-gettypestring-typename-returns-null
原文:
If you know that whatever type it is will be within DataAccessLayer
, then I'd get an Assembly
reference as simply as possible, e.g.
Assembly assembly = typeof(AnyPublicTypeWithinTargetAssembly).Assembly;
Type type = assembly.GetType(namespaceQualifiedTypeName);
An alternative is to use Type.GetType
with an assembly-qualified name, but that's more long-winded in terms of specifying the type name.