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


C# Assembly.GetAccessibleTypes方法代码示例

本文整理汇总了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;
        }
开发者ID:hallco978,项目名称:entityframework,代码行数:25,代码来源:DbConfigurationFinder.cs

示例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();
        }
开发者ID:WangWilliam,项目名称:EntityFramework5,代码行数:17,代码来源:MigrationAssembly.cs

示例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();
        }
开发者ID:hallco978,项目名称:entityframework,代码行数:40,代码来源:DbConfigurationFinder.cs


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