C#可以减少或不使用switch有什么方法

2019-05-20 12:12:08于丽

上面的最终代码,无传入参数mothedName,怎样办,我们可以虑一下反射,如果改为反射击,那传入的参数需要规范一下方可以:
"get" >>"Get";
"get1" >>"GetTest"
"testget" >> "GetSet"
这样一改之后,就可以使用反射语法了,可以把

IGetFactory get = new GetTestFactory(); //这里是实现工厂类

改为(下面是asp.net的应用):

IGetFactory get = (IGetFactory)Assembly.Load("App_Code").CreateInstance("Insus.NET." + mothedName + "Factory");

如果在非asp.net下,可以把"App_Code"改为"程序集名称":

IGetFactory get = (IGetFactory)Assembly.Load("程序集名称").CreateInstance("Insus.NET." + mothedName + "Factory");