调用可配置方法的最佳方法

Ang*_*Bad 1 c# configuration

我需要找出调用statc方法的最佳方法,我只在运行时在运行时知道.

每个使用我软件的客户都有一个返回suctom字符串的特殊方法.我想将方法​​名称放在配置文件中,然后在运行时调用它.

这是一个好方法吗?

ono*_*nof 5

为什么不实现给定接口的自定义类?它应该更好,IMO.

您可以将完全限定的类名放在配置中,并通过反射实例化它:

Type t = Type.GetType(type_name_from_config);

IGivenInterface obj = (IGivenInterface) Activator.CreateInstance(t);
Run Code Online (Sandbox Code Playgroud)