C# - How to check if namespace, class or method exists in C#?
问题 I have a C# program, how can I check at runtime if a namespace, class, or method exists? Also, how to instantiate a class by using it's name in the form of string? Pseudocode: string @namespace = "MyNameSpace"; string @class = "MyClass"; string method= "MyMEthod"; var y = IsNamespaceExists(namespace); var x = IsClassExists(@class)? new @class : null; //Check if exists, instantiate if so. var z = x.IsMethodExists(method); 回答1: You can use Type.GetType(string) to reflect a type. GetType will