How to get a type for a class by sending only the class name instead of the class itself as a parameter?

Dim a as Type = GetType (className) will return a type. But I only have the class name as a string. I want something like GetType ("class1") that will return a type.

+3
source share
2 answers
Type.GetType("class1")
+6
source

Both types Type.GetType (...) and Assembly.GetType (...) assume the full type name. Thus, only passing a class name without its namespace will not result in a type.

If you include the namespace like this:

Type.GetType("Fully.Qualified.Namespace.class1")

will give the same result as GetType (class1).

: , ( Linq mind you) :

GetType().Assembly.GetTypes().First(type => type.Name == "AssemblyModuleTests")

, , , GetTypes() .

+1

Source: https://habr.com/ru/post/1717446/


All Articles