一般的接口实现多态

定义接口

    interface ipeople
    {
        void say();
    }

定义实现的类

  public class man : ipeople
    {
        public void say()
        {
            messagebox.show("man");
        }
    }

 public class woman : ipeople
    {
        public void say()
        {
            messagebox.show("woman");
        }
    }

一般实现的方法

升级版

添加自定义(这个网上好多)

实现类

调用方法

   private static void newmethod(string tpye)
        {
            ipeople ib = null;
            var types = appdomain.currentdomain.getassemblies()
                        .selectmany(a => a.gettypes().where(t => t.getinterfaces().contains(typeof(ipeople))))
                        .toarray();
            foreach (var v in types)
            {
                var attribute = v.getcustomattributes(typeof(nameattribute), false).firstordefault();
                if (attribute != null && ((nameattribute)attribute).name == tpye)
                {
                    ib = (ipeople)v.assembly.createinstance(v.fullname);
                    break;
                }
            }
            if (ib != null) ib.say();
        }

这个可以避免需要维护swich语句