Get type in referenced assembly by supplying class name as string?

后端 未结 2 912
南方客
南方客 2020-12-29 12:07

These are similar questions: How-to: Load a type from a referenced assembly at runtime using a string in Silverlight, GetType on a class in a referenced assembly fails but n

2条回答
  •  北荒
    北荒 (楼主)
    2020-12-29 12:40

    For the first question, you could do something like

    Type t = AppDomain.CurrentDomain.GetAssemblies()
                                    .Where(a => a.FullName == "MyFramework")
                                    .SelectMany(a => a.GetTypes())
                                    .Where(t => t.Name == "Car")
                                    .FirstOrDefault();
    

    I am not sure what you mean by the second question.

提交回复
热议问题