Exemplo n.º 1
0
        /// <summary>
        /// 获取给定类型的ORM支持成员
        /// </summary>
        /// <param name="type"></param>
        /// <param name="includePrivate">包含私有成员</param>
        /// <returns></returns>
        public static IEnumerable <MemberInfo> GetMembers(Type type, bool includePrivate = false)
        {
            Func <MemberInfo, bool> predicate = x => x.MemberType == MemberTypes.Method || x.MemberType == MemberTypes.Field || x.MemberType == MemberTypes.Property;
            BindingFlags            flags     = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public;

            if (includePrivate)
            {
                flags = flags | BindingFlags.NonPublic;
            }
            var collection =
                type
                .GetMembers(flags)
                .Where(predicate);

            if (type.IsInterface)
            {
                var inheritsTypes = type.GetInterfaces();
                foreach (var ihType in inheritsTypes)
                {
                    var second = TypeUtils.GetMembers(ihType);
                    collection = collection.Union(second);
                }
            }

            return(collection);
        }
Exemplo n.º 2
0
 /// <summary>
 /// 获取当前类型的成员
 /// </summary>
 protected virtual IEnumerable <MemberInfo> GetMembers(Type type)
 {
     return(TypeUtils.GetMembers(type));
 }
Exemplo n.º 3
0
 /// <summary>
 /// 获取当前类型的所有成员
 /// </summary>
 protected virtual IEnumerable <MemberInfo> GetTypeMembers(Type type, bool @private)
 {
     return(TypeUtils.GetMembers(type, @private));
 }