Beispiel #1
0
        /// <summary>
        /// 反射模式对象扫描
        /// </summary>
        /// <param name="scanner">类型扫描</param>
        /// <param name="fieldInfo">当前扫描静态字段</param>
        internal ReflectionScanner(ReflectionTypeScanner scanner, FieldInfo fieldInfo)
        {
            Scanner          = scanner;
            FieldInfo        = fieldInfo;
            objectReferences = HashSetCreator <ObjectReference> .Create();

            Arrays          = new LeftArray <ReflectionArrayScanner>(0);
            Objects         = new LeftArray <ReflectionObjectScanner>(0);
            IsLimitExceeded = false;
        }
        /// <summary>
        /// 转换HASH
        /// </summary>
        /// <typeparam name="valueType">数据类型</typeparam>
        /// <typeparam name="hashType">目标数据类型</typeparam>
        /// <param name="array">数组数据</param>
        /// <param name="getValue">数据获取器</param>
        /// <returns>HASH</returns>
        public static HashSet <hashType> getHash <valueType, hashType>(this valueType[] array, Func <valueType, hashType> getValue)
        {
            if (array != null)
            {
                HashSet <hashType> hash = HashSetCreator <hashType> .Create();

                foreach (valueType value in array)
                {
                    hash.Add(getValue(value));
                }
                return(hash);
            }
            return(null);
        }
Beispiel #3
0
        /// <summary>
        /// 分组列表 延时排序缓存
        /// </summary>
        /// <param name="cache">整表缓存</param>
        /// <param name="getKey">分组字典关键字获取器</param>
        /// <param name="getValue">获取目标对象委托</param>
        /// <param name="member">缓存字段表达式</param>
        /// <param name="getTargets"></param>
        /// <param name="sorter">排序器</param>
        /// <param name="isReset">是否初始化</param>
        public MemberOrderList(Event.Cache <valueType, modelType> cache, Func <modelType, keyType> getKey
                               , Func <keyType, targetType> getValue, Expression <Func <targetType, ListArray <valueType> > > member
                               , Func <IEnumerable <targetType> > getTargets, Func <LeftArray <valueType>, LeftArray <valueType> > sorter, bool isReset)
            : base(cache, getKey, getValue, member, getTargets)
        {
            if (sorter == null)
            {
                throw new ArgumentNullException();
            }
            this.sorter = sorter;

            if (isReset)
            {
                HashSet <keyType> keys = HashSetCreator <keyType> .Create();

                foreach (valueType value in cache.Values)
                {
                    keyType    key    = getKey(value);
                    targetType target = getValue(key);
                    if (target == null)
                    {
                        cache.SqlTable.Log.Debug(typeof(valueType).FullName + " 没有找到缓存目标对象 " + key.ToString(), LogLevel.Debug | LogLevel.Info | LogLevel.AutoCSer);
                    }
                    else
                    {
                        ListArray <valueType> list = getMember(target);
                        if (list == null)
                        {
                            (list = new ListArray <valueType>()).Add(value);
                            setMember(target, list);
                        }
                        else
                        {
                            list.Add(value);
                            keys.Add(key);
                        }
                    }
                }
                foreach (keyType key in keys)
                {
                    ListArray <valueType> list = getMember(getValue(key));
                    list.Array = sorter(list.Array);
                    //list.Array.Array = list.Array.Array.notNull();
                }
                cache.OnInserted += onInserted;
                cache.OnUpdated  += onUpdated;
                cache.OnDeleted  += onDeleted;
            }
        }
Beispiel #4
0
        /// <summary>
        /// 转换HASH
        /// </summary>
        /// <typeparam name="T">数据类型</typeparam>
        /// <typeparam name="VT">目标数据类型</typeparam>
        /// <param name="array">数组数据</param>
        /// <param name="getValue">数据获取器</param>
        /// <returns>HASH</returns>
        public static HashSet <VT> getHash <T, VT>(this T[] array, Func <T, VT> getValue)
            where VT : IEquatable <VT>
        {
            if (array != null)
            {
                HashSet <VT> hash = HashSetCreator <VT> .Create();

                foreach (T value in array)
                {
                    hash.Add(getValue(value));
                }
                return(hash);
            }
            return(null);
        }