Automatonymous.Tests.InterfaceReflectionCache.Get C# (CSharp) Метод

Get() публичный Метод

public Get ( Type type, Type interfaceType ) : Type
type System.Type
interfaceType System.Type
Результат System.Type
        public Type Get(Type type, Type interfaceType)
        {
            ConcurrentDictionary<Type, Type> typeCache = _cache.GetOrAdd(type, x => new ConcurrentDictionary<Type, Type>());

            return typeCache.GetOrAdd(interfaceType, x => GetInterfaceInternal(type, interfaceType));
        }

Usage Example

        public static Type GetInterface(this Type type, Type interfaceType)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }
            if (interfaceType == null)
            {
                throw new ArgumentNullException(nameof(interfaceType));
            }

            var interfaceTypeInfo = interfaceType.GetTypeInfo();

            if (!interfaceTypeInfo.IsInterface)
            {
                throw new ArgumentException("The interface type must be an interface: " + interfaceType.Name);
            }

            return(_cache.Get(type, interfaceType));
        }