Exemple #1
0
        ///// <summary>
        ///// 拥有指定类型转换器的转换
        ///// </summary>
        ///// <param name="collection"></param>
        ///// <param name="func"></param>
        ///// <returns></returns>
        //public static ListX<T> From(IEnumerable collection, Func<Object, T> func)
        //{
        //    if (collection == null || collection.GetEnumerator() == null || collection.GetEnumerator().Current == null) return null;

        //    ListX<T> list = new ListX<T>();
        //    foreach (Object item in collection)
        //    {
        //        if (func == null)
        //            list.Add((T)item);
        //        else
        //            list.Add(func(item));
        //    }
        //    if (list == null || list.Count < 1) return null;
        //    return list;
        //}

        /// <summary>
        /// 拥有指定类型转换器的转换
        /// </summary>
        /// <typeparam name="T2"></typeparam>
        /// <param name="collection"></param>
        /// <param name="func"></param>
        /// <returns></returns>
        public static ListX <T> From <T2>(IEnumerable collection, ITOrm.EF.Models.Reflection.Func <T2, T> func)
        {
            if (collection == null || collection.GetEnumerator() == null)
            {
                return(null);
            }

            ListX <T> list = new ListX <T>();

            foreach (T2 item in collection)
            {
                if (item == null)
                {
                    continue;
                }
                T entity = default(T);
                if (func == null)
                {
                    entity = (T)(Object)item;
                }
                else
                {
                    entity = func(item);
                }
                if (entity != null)
                {
                    list.Add(entity);
                }
            }
            if (list == null || list.Count < 1)
            {
                return(null);
            }
            return(list);
        }
Exemple #2
0
        /// <summary>
        /// 检索与指定谓词定义的条件匹配的所有元素。
        /// </summary>
        /// <param name="match">条件</param>
        /// <returns></returns>
        public new ListX <T> FindAll(Predicate <T> match)
        {
            if (Count < 1)
            {
                return(null);
            }

            ListX <T> list = new ListX <T>();

            foreach (T item in this)
            {
                if (item == null)
                {
                    continue;
                }
                if (match(item))
                {
                    list.Add(item);
                }
            }
            if (list == null || list.Count < 1)
            {
                return(null);
            }
            return(list);
        }
Exemple #3
0
        /// <summary>
        /// 根据指定项查找字符串。忽略大小写
        /// </summary>
        /// <param name="name">属性名</param>
        /// <param name="value">属性值</param>
        /// <returns></returns>
        public ListX <T> FindAllIgnoreCase(String name, String value)
        {
            if (Count < 1)
            {
                return(null);
            }

            ListX <T> list = new ListX <T>();

            foreach (T item in this)
            {
                if (item == null)
                {
                    continue;
                }
                if (String.Equals((String)GetValue(item, name), value, StringComparison.OrdinalIgnoreCase))
                {
                    list.Add(item);
                }
            }
            if (list == null || list.Count < 1)
            {
                return(null);
            }
            return(list);
        }
Exemple #4
0
        /// <summary>
        /// 根据指定项查找
        /// </summary>
        /// <param name="name">属性名</param>
        /// <param name="value">属性值</param>
        /// <returns></returns>
        public ListX <T> FindAll(String name, Object value)
        {
            if (Count < 1)
            {
                return(null);
            }

            ListX <T> list = new ListX <T>();

            foreach (T item in this)
            {
                if (item == null)
                {
                    continue;
                }
                //if (Object.Equals(GetValue(item, name), value)) list.Add(item);
                if (Object.Equals(GetValue(item, name), value))
                {
                    list.Add(item);
                }
            }
            if (list == null || list.Count < 1)
            {
                return(null);
            }
            return(list);
        }
Exemple #5
0
        //static ListX<MemberInfo> GetMembers(Type type)
        //{
        //    ListX<MemberInfo> list = new ListX<MemberInfo>();
        //    MemberInfo[] mis = type.GetMembers(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
        //    if (mis != null && mis.Length > 0) list.AddRange(mis);

        //    if (type.BaseType != null)
        //    {
        //        ListX<MemberInfo> list2 = GetMembers(type.BaseType);
        //        if (list2 != null) list.AddRange(list2);
        //    }

        //    if (list.Count < 1) return null;
        //    return list;
        //}

        ListX <T> GetMembers <T>(MemberTypes memberType) where T : MemberInfo
        {
            if (Members == null || Members.Count < 1)
            {
                return(null);
            }

            ListX <T> list = new ListX <T>();

            foreach (MemberInfo item in Members)
            {
                if (item.MemberType == memberType)
                {
                    list.Add(item as T);
                }
            }
            return(list.Count > 0 ? list : null);
        }
Exemple #6
0
        /// <summary>
        /// 查找插件,带缓存
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public ListX <Type> FindPlugins(Type type)
        {
            ListX <Type> list = null;

            if (_plugins.TryGetValue(type, out list))
            {
                return(list);
            }
            lock (_plugins)
            {
                if (_plugins.TryGetValue(type, out list))
                {
                    return(list);
                }

                ListX <TypeX> list2 = TypeXs;
                if (list2 == null || list2.Count < 1)
                {
                    list = null;
                }
                else
                {
                    list = new ListX <Type>();
                    foreach (TypeX item in list2)
                    {
                        if (item.IsPlugin(type))
                        {
                            list.Add(item.Type);
                        }
                    }
                    if (list.Count <= 0)
                    {
                        list = null;
                    }
                }

                _plugins.Add(type, list);

                return(list);
            }
        }
Exemple #7
0
        /// <summary>
        /// 只反射加载有效路径(应用程序是当前路径,Web是Bin目录)的所有程序集
        /// </summary>
        /// <param name="domain"></param>
        /// <returns></returns>
        public static ListX <AssemblyX> ReflectionOnlyGetAssemblies(AppDomain domain)
        {
            if (domain == null)
            {
                domain = AppDomain.CurrentDomain;
            }

            Assembly[] asms = domain.ReflectionOnlyGetAssemblies();
            if (asms == null || asms.Length < 1)
            {
                return(null);
            }

            ListX <AssemblyX> list = new ListX <AssemblyX>();

            foreach (Assembly item in asms)
            {
                list.Add(AssemblyX.Create(item));
            }

            return(list);
        }
Exemple #8
0
        /// <summary>
        /// 集合相减
        /// </summary>
        /// <param name="list1">第一个实体集合</param>
        /// <param name="list2">第二个实体集合</param>
        /// <returns></returns>
        public static ListX <T> operator -(ListX <T> list1, ListX <T> list2)
        {
            if (list1 == null || list1.Count < 1)
            {
                return(null);
            }

            ListX <T> list = new ListX <T>();

            foreach (T item in list1)
            {
                if (list2 != null && !list2.Contains(item))
                {
                    list.Add(item);
                }
            }

            if (list == null || list.Count < 1)
            {
                return(null);
            }

            return(list);
        }
Exemple #9
0
        /// <summary>
        /// 只反射加载指定路径的所有程序集
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public static ListX <AssemblyX> ReflectionOnlyLoad(String path)
        {
            if (!Directory.Exists(path))
            {
                return(null);
            }

            String[] ss = Directory.GetFiles(path, "*.*", SearchOption.TopDirectoryOnly);
            if (ss == null || ss.Length < 1)
            {
                return(null);
            }

            //AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve += new ResolveEventHandler(CurrentDomain_ReflectionOnlyAssemblyResolve);

            //try
            {
                ListX <AssemblyX> loadeds  = AssemblyX.GetAssemblies();
                ListX <AssemblyX> loadeds2 = AssemblyX.ReflectionOnlyGetAssemblies();

                ListX <AssemblyX> list = new ListX <AssemblyX>();
                foreach (String item in ss)
                {
                    if (!item.EndsWith(".dll", StringComparison.OrdinalIgnoreCase) &&
                        !item.EndsWith(".exe", StringComparison.OrdinalIgnoreCase))
                    {
                        continue;
                    }

                    if (loadeds != null && loadeds.Exists(delegate(AssemblyX elm)
                    {
                        return(item.Equals(elm.Asm.Location, StringComparison.OrdinalIgnoreCase));
                    }))
                    {
                        continue;
                    }

                    if (loadeds2 != null && loadeds2.Exists(delegate(AssemblyX elm)
                    {
                        return(item.Equals(elm.Asm.Location, StringComparison.OrdinalIgnoreCase));
                    }))
                    {
                        continue;
                    }

                    try
                    {
                        //Assembly asm = Assembly.ReflectionOnlyLoad(File.ReadAllBytes(item));
                        Assembly asm = Assembly.ReflectionOnlyLoadFrom(item);

                        list.Add(AssemblyX.Create(asm));
                    }
                    catch { }
                }

                return(list);
            }
            //finally
            //{
            //    AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve -= new ResolveEventHandler(CurrentDomain_ReflectionOnlyAssemblyResolve);
            //}
        }