This repository has been archived on 2024-01-02. You can view files and clone it, but cannot push or open issues or pull requests.
Sic06/FrameworkLocal/UIClient/Core/Container/ParameterCache.cs

30 lines
988 B
C#
Raw Normal View History

2023-01-13 10:57:37 +08:00
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
namespace OpenSEMI.Core.Container
{
internal class ParameterCache
{
private static ConcurrentDictionary<ConstructorInfo, List<ParameterInfo>> _parameterCache = new ConcurrentDictionary<ConstructorInfo, List<ParameterInfo>>();
public static List<ParameterInfo> GetParameters(ConstructorInfo constructor)
{
List<ParameterInfo> parameterInfo;
if (!_parameterCache.TryGetValue(constructor, out parameterInfo))
{
// Not in cache, discover and add to cache.
parameterInfo = _parameterCache[constructor] = DiscoverParameters(constructor);
}
return parameterInfo;
}
private static List<ParameterInfo> DiscoverParameters(ConstructorInfo constructor)
{
return constructor.GetParameters().ToList();
}
}
}