ActivatorCreatePool.cs 793 B

12345678910111213141516171819202122232425262728293031
  1. using System;
  2. namespace IFramework
  3. {
  4. /// <summary>
  5. /// Activator 创建实例 对现池
  6. /// </summary>
  7. /// <typeparam name="T"></typeparam>
  8. public class ActivatorCreatePool<T> : ObjectPool<T>
  9. {
  10. private object[] args;
  11. /// <summary>
  12. /// ctor
  13. /// </summary>
  14. /// <param name="args">构造固定参数</param>
  15. public ActivatorCreatePool(params object[] args)
  16. {
  17. this.args = args;
  18. }
  19. /// <summary>
  20. /// 创建
  21. /// </summary>
  22. /// <param name="arg"></param>
  23. /// <returns></returns>
  24. protected override T CreateNew(IEventArgs arg)
  25. {
  26. Type type = typeof(T);
  27. return (T)Activator.CreateInstance(type, args);
  28. }
  29. }
  30. }