简易版ioc
public class Container { private Dictionary<Type, Type> _dataDic = null; // 问题1,构造函数属性赋值 public Container() { _dataDic = new Dictionary<Type, Type>(1); } public void RegistType<T1, T2>() { _dataDic.Add(typeof(T1), typeof(T2)); } // 问题2,子类和父类是一种类型 public T ReSolve<T>() { return (T)Activator.CreateInstance(_dataDic[typeof(T)]); } }