ParameterCache.cs 822 B

1234567891011121314151617181920212223242526272829
  1. using System.Collections.Concurrent;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Reflection;
  5. namespace OpenSEMI.Core.Container
  6. {
  7. internal class ParameterCache
  8. {
  9. private static ConcurrentDictionary<ConstructorInfo, List<ParameterInfo>> _parameterCache = new ConcurrentDictionary<ConstructorInfo, List<ParameterInfo>>();
  10. public static List<ParameterInfo> GetParameters(ConstructorInfo constructor)
  11. {
  12. if (!_parameterCache.TryGetValue(constructor, out List<ParameterInfo> value))
  13. {
  14. List<ParameterInfo> list2 = _parameterCache[constructor] = DiscoverParameters(constructor);
  15. value = list2;
  16. return value;
  17. }
  18. return value;
  19. }
  20. private static List<ParameterInfo> DiscoverParameters(ConstructorInfo constructor)
  21. {
  22. return constructor.GetParameters().ToList();
  23. }
  24. }
  25. }