本文整理汇总了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;
}
示例2: IsStructuralTypeConfiguration
private static bool IsStructuralTypeConfiguration(Type type, Type structuralTypeConfiguration)
{
DebugCheck.NotNull(type);
DebugCheck.NotNull(structuralTypeConfiguration);
return !type.IsAbstract && type.TryGetElementType(structuralTypeConfiguration) != null;
}
示例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;
}
示例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;
}
示例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;
}