예제 #1
0
            private void InitConfigurations()
            {
                if (_extendConfigurations == null)
                {
                    /*********************** 代码块解释 *********************************
                     * 查找所有 EntityConfig 类型,并根据是否为扩展视图的配置类,
                     * 分别加入到两个不同的列表中。
                     **********************************************************************/

                    var defaultRepo = new Dictionary <Type, List <TViewConfig> >(100);
                    var extendRepo  = new Dictionary <ExtendTypeKey, List <TViewConfig> >(100);
                    var entityType  = typeof(TViewConfig);

                    //视图配置可以放在所有插件中。
                    for (int index = 0, c = RafyEnvironment.AllPlugins.Count; index < c; index++)
                    {
                        var plugin = RafyEnvironment.AllPlugins[index];
                        foreach (var type in plugin.Assembly.GetTypes())
                        {
                            if (!type.IsGenericTypeDefinition && !type.IsAbstract && entityType.IsAssignableFrom(type))
                            {
                                var config = Activator.CreateInstance(type) as TViewConfig;
                                config.PluginIndex      = index;
                                config.InheritanceCount = TypeHelper.GetHierarchy(type, typeof(ManagedPropertyObject)).Count();

                                List <TViewConfig> typeList = null;

                                if (config.ExtendView == null)
                                {
                                    if (!defaultRepo.TryGetValue(config.EntityType, out typeList))
                                    {
                                        typeList = new List <TViewConfig>(2);
                                        defaultRepo.Add(config.EntityType, typeList);
                                    }
                                }
                                else
                                {
                                    var key = new ExtendTypeKey {
                                        EntityType = config.EntityType, ExtendView = config.ExtendView
                                    };
                                    if (!extendRepo.TryGetValue(key, out typeList))
                                    {
                                        typeList = new List <TViewConfig>(2);
                                        extendRepo.Add(key, typeList);
                                    }
                                }

                                typeList.Add(config);
                            }
                        }
                    }

                    _configurations       = defaultRepo;
                    _extendConfigurations = extendRepo;
                }
            }
예제 #2
0
            /// <summary>
            /// 获取某个实体视图的所有配置类实例
            /// </summary>
            /// <param name="entityType"></param>
            /// <param name="extendView">如果想获取扩展视图列表,则需要传入指定的扩展视图列表</param>
            /// <returns></returns>
            internal IEnumerable <TViewConfig> FindViewConfigurations(Type entityType, string extendView = null)
            {
                InitConfigurations();

                var hierachy = TypeHelper.GetHierarchy(entityType, typeof(ManagedPropertyObject)).Reverse();

                if (extendView == null)
                {
                    foreach (var type in hierachy)
                    {
                        List <TViewConfig> configList = null;
                        if (_configurations.TryGetValue(type, out configList))
                        {
                            var orderedList = configList.OrderBy(o => o.PluginIndex).ThenBy(o => o.InheritanceCount);
                            foreach (var config in orderedList)
                            {
                                yield return(config);
                            }
                        }
                    }
                }
                else
                {
                    foreach (var type in hierachy)
                    {
                        var key = new ExtendTypeKey {
                            EntityType = type, ExtendView = extendView
                        };

                        List <TViewConfig> configList = null;
                        if (_extendConfigurations.TryGetValue(key, out configList))
                        {
                            var orderedList = configList.OrderBy(o => o.PluginIndex).ThenBy(o => o.InheritanceCount);
                            foreach (var config in orderedList)
                            {
                                yield return(config);
                            }
                        }
                    }
                }
            }