Пример #1
0
        public IDataProvider GetProvider(Type type)
        {
            if (TypeProviders.TryGetValue(type, out var result))
            {
                return(result);
            }

            var factory = GetProviderFactory(type);

            if (factory != null)
            {
                lock (TypeProviders)
                    return(TypeProviders[type] = factory.GetProvider(type));
            }

            if (type.IsInterface)
            {
                return(new InterfaceDataProvider(type));
            }
            else
            {
                throw new InvalidOperationException("There is no registered 'data provider' for the assembly: " +
                                                    type.GetTypeInfo().Assembly.FullName);
            }
        }
        public IDataProvider GetProviderOrNull(Type type)
        {
            if (TypeProviders.TryGetValue(type, out var result))
            {
                return(result);
            }

            var factory = GetProviderFactory(type);

            if (factory != null)
            {
                lock (TypeProviders)
                {
                    try
                    {
                        return(TypeProviders[type] = factory.GetProvider(type));
                    }
                    catch
                    {
                        return(null);
                    }
                }
            }

            if (type.IsInterface)
            {
                return(new InterfaceDataProvider(type));
            }
            else
            {
                return(null);
            }
        }