When does `Assembly.GetType(name)` return `null`?

后端 未结 6 1760
太阳男子
太阳男子 2021-01-12 17:47

I have a code like shown below

public static Type ToType(Type sType)
{    
    Assembly assembly = Assembly.Load(SerializableType.AssemblyName);
    type = a         


        
6条回答
  •  天命终不由人
    2021-01-12 18:04

    Here is an actual example from a UWP app. The app namespace is My_App. Class FooPage is under folder Views. The way to get the Type is the following:

    Type typePage = Assembly.GetExecutingAssembly().GetType("My_App.Views.FooPage}");
    

    If you are not sure about the name of your type, use the following code to dump all classes and find the one of interest:

    foreach(Type t in Assembly.GetExecutingAssembly().GetTypes())
    {
        Debug.WriteLine($"{t.Namespace}.{t.Name}");
    }
    

提交回复
热议问题