当前位置: 首页>>代码示例>>C#>>正文


C# Type.TryGetElementType方法代码示例

本文整理汇总了C#中Type.TryGetElementType方法的典型用法代码示例。如果您正苦于以下问题:C# Type.TryGetElementType方法的具体用法?C# Type.TryGetElementType怎么用?C# Type.TryGetElementType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Type的用法示例。


在下文中一共展示了Type.TryGetElementType方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetServiceFactory

        public virtual Func<object> GetServiceFactory(Type type, string name)
        {
            if (!string.IsNullOrWhiteSpace(name))
            {
                if (type == typeof(DbProviderServices))
                {
                    var providerServices = _appConfig.Providers.TryGetDbProviderServices(name);
                    return () => providerServices;
                }

                if (type == typeof(MigrationSqlGenerator))
                {
                    return _appConfig.Providers.TryGetMigrationSqlGeneratorFactory(name);
                }
            }

            if (type == typeof(IDbConnectionFactory))
            {
                var connectionFactory = _appConfig.TryGetDefaultConnectionFactory();
                return () => connectionFactory;
            }

            var contextType = type.TryGetElementType(typeof(IDatabaseInitializer<>));
            if (contextType != null)
            {
                var initializer = _appConfig.Initializers.TryGetInitializer(contextType);
                return () => initializer;
            }

            return () => null;
        }
开发者ID:junxy,项目名称:entityframework,代码行数:31,代码来源:AppConfigDependencyResolver.cs

示例2: IsStructuralTypeConfiguration

        private static bool IsStructuralTypeConfiguration(Type type, Type structuralTypeConfiguration)
        {
            DebugCheck.NotNull(type);
            DebugCheck.NotNull(structuralTypeConfiguration);

            return !type.IsAbstract && type.TryGetElementType(structuralTypeConfiguration) != null;
        }
开发者ID:christiandpena,项目名称:entityframework,代码行数:7,代码来源:ConfigurationTypeFilter.cs

示例3: GetService

        public object GetService(Type type, object key)
        {
            Check.NotNull(type, "type");

            var contextType = type.TryGetElementType(typeof(IDatabaseInitializer<>));
            if (contextType != null
                && typeof(TransactionContext).IsAssignableFrom(contextType))
            {
                return _initializers.GetOrAdd(contextType, CreateInitializerInstance);
            }

            return null;
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:13,代码来源:TransactionContextInitializerResolver.cs

示例4: GetService

        public virtual object GetService(Type type, object key)
        {
            var contextType = type.TryGetElementType(typeof(IDatabaseInitializer<>));
            if (contextType != null)
            {
                object initializer;
                if (_initializers.TryGetValue(contextType, out initializer))
                {
                    return initializer;
                }
            }

            return null;
        }
开发者ID:christiandpena,项目名称:entityframework,代码行数:14,代码来源:DatabaseInitializerResolver.cs

示例5: GetServiceFactory

        public virtual Func<object> GetServiceFactory(Type type, string name)
        {
            if (!_providersRegistered)
            {
                lock (_providerFactories)
                {
                    if (!_providersRegistered)
                    {
                        RegisterDbProviderServices();
                        _providersRegistered = true;
                    }
                }
            }

            if (!string.IsNullOrWhiteSpace(name))
            {
                if (type == typeof(DbProviderServices))
                {
                    DbProviderServices providerFactory;
                    _providerFactories.TryGetValue(name, out providerFactory);
                    return () => providerFactory;
                }
            }

            if (type == typeof(IDbConnectionFactory))
            {
                // This is convoluted to avoid breaking changes from EF5. The behavior is:
                // 1. If the app has already set the Database.DefaultConnectionFactory property, then
                //    whatever it is set to should be returned.
                // 2. If not, but an connection factory was set in app.config, then set the
                //    DefaultConnectionFactory property to the one from the app.config so that in
                //    the future it will always be used, unless...
                // 3. The app later changes the DefaultConnectionFactory property in which case
                //    the later one will be used instead of the one from app.config
                // Note that this means that the app.config and DefaultConnectionFactory will override
                // any other resolver in the chain (since this class is at the top of the chain)
                // unless IDbConfiguration was used to add an overriding resolver.
                if (!Database.DefaultConnectionFactoryChanged)
                {
                    var connectionFactory = _appConfig.TryGetDefaultConnectionFactory();
                    if (connectionFactory != null)
                    {
#pragma warning disable 612,618
                        Database.DefaultConnectionFactory = connectionFactory;
#pragma warning restore 612,618
                    }
                }

                return () => Database.DefaultConnectionFactoryChanged ? Database.SetDefaultConnectionFactory : null;
            }

            var contextType = type.TryGetElementType(typeof(IDatabaseInitializer<>));
            if (contextType != null)
            {
                var initializer = _appConfig.Initializers.TryGetInitializer(contextType);
                return () => initializer;
            }

            return () => null;
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:60,代码来源:AppConfigDependencyResolver.cs


注:本文中的Type.TryGetElementType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。