本文整理汇总了C#中System.Reflection.Assembly.GetAccessibleTypes方法的典型用法代码示例。如果您正苦于以下问题:C# Assembly.GetAccessibleTypes方法的具体用法?C# Assembly.GetAccessibleTypes怎么用?C# Assembly.GetAccessibleTypes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.Assembly
的用法示例。
在下文中一共展示了Assembly.GetAccessibleTypes方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryFindContextType
public virtual Type TryFindContextType(
Assembly assemblyHint,
Type contextTypeHint,
IEnumerable<Type> typesToSearch = null)
{
if (contextTypeHint != null)
{
return contextTypeHint;
}
// If no context type is known then try to find a single DbContext in the given assembly that
// is attributed with the DbConfigurationTypeAttribute. This is a heuristic for tooling such
// that if tooling only knows the assembly, but the assembly has a DbContext type in it, and
// that DbContext type is attributed, then tooling will use the configuration specified in that
// attribute.
var contextTypes = (typesToSearch ?? assemblyHint.GetAccessibleTypes())
.Where(
t => t.IsSubclassOf(typeof(DbContext))
&& !t.IsAbstract
&& !t.IsGenericType
&& t.GetCustomAttributes(typeof(DbConfigurationTypeAttribute), inherit: true).Any())
.ToList();
return contextTypes.Count == 1 ? contextTypes[0] : null;
}
示例2: MigrationAssembly
public MigrationAssembly(Assembly migrationsAssembly, string migrationsNamespace)
{
Contract.Requires(migrationsAssembly != null);
_migrations
= (from t in migrationsAssembly.GetAccessibleTypes()
where t.IsSubclassOf(typeof(DbMigration))
&& typeof(IMigrationMetadata).IsAssignableFrom(t)
&& t.GetConstructor(Type.EmptyTypes) != null
&& !t.IsAbstract
&& !t.IsGenericType
&& t.Namespace == migrationsNamespace
select (IMigrationMetadata)Activator.CreateInstance(t))
.Where(mm => !string.IsNullOrWhiteSpace(mm.Id) && mm.Id.IsValidMigrationId())
.OrderBy(mm => mm.Id)
.ToList();
}
示例3: TryFindConfigurationType
public virtual Type TryFindConfigurationType(
Assembly assemblyHint,
Type contextTypeHint,
IEnumerable<Type> typesToSearch = null)
{
DebugCheck.NotNull(assemblyHint);
if (contextTypeHint != null)
{
var typeFromAttribute = contextTypeHint.GetCustomAttributes(inherit: true)
.OfType<DbConfigurationTypeAttribute>()
.Select(a => a.ConfigurationType)
.FirstOrDefault();
if (typeFromAttribute != null)
{
if (!typeof(DbConfiguration).IsAssignableFrom(typeFromAttribute))
{
throw new InvalidOperationException(
Strings.CreateInstance_BadDbConfigurationType(typeFromAttribute.ToString(), typeof(DbConfiguration).ToString()));
}
return typeFromAttribute;
}
}
var configurations = (typesToSearch ?? assemblyHint.GetAccessibleTypes())
.Where(
t => t.IsSubclassOf(typeof(DbConfiguration))
&& !t.IsAbstract
&& !t.IsGenericType)
.ToList();
if (configurations.Count > 1)
{
throw new InvalidOperationException(
Strings.MultipleConfigsInAssembly(configurations.First().Assembly, typeof(DbConfiguration).Name));
}
return configurations.FirstOrDefault();
}