Exemplo n.º 1
0
        /// <summary>
        /// 获取Field列表
        /// </summary>
        public static List <FieldInfo> GetFieldList(Type t)
        {
            string key = t.GUID.ToString();

            if (fieldCache.ContainsKey(key))
            {
                return(fieldCache[key]);
            }
            else
            {
                bool             isInheritOrm = t.BaseType.Name == "OrmBase" || t.BaseType.Name == "SimpleOrmBase";
                FieldInfo[]      pInfo        = isInheritOrm ? t.GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly) : t.GetFields();
                List <FieldInfo> list         = new List <FieldInfo>(pInfo.Length);
                try
                {
                    list.AddRange(pInfo);
                    fieldCache.Set(key, list);
                }
                catch (Exception err)
                {
                    Log.Write(err, LogType.Error);
                }
                return(list);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 获取属性列表
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        internal static List <PropertyInfo> GetPropertyInfo(Type t)
        {
            string key = t.GUID.ToString();

            if (propCache.ContainsKey(key))
            {
                return(propCache[key]);
            }
            else
            {
                bool                isInheritOrm = t.BaseType.Name == "OrmBase" || t.BaseType.Name == "SimpleOrmBase";
                PropertyInfo[]      pInfo        = isInheritOrm ? t.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly) : t.GetProperties();
                List <PropertyInfo> list         = new List <PropertyInfo>(pInfo.Length);
                try
                {
                    list.AddRange(pInfo);
                    propCache.Set(key, list);
                }
                catch (Exception err)
                {
                    Log.WriteLogToTxt(err);
                }
                return(list);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 获取属性列表
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public static List <PropertyInfo> GetPropertyList(Type t)
        {
            bool   isAnonymousType = t.Name.Contains("f__AnonymousType"); //忽略匿名类型
            string key             = t.FullName;                          // t.GUID.ToString();由泛型 XX<T> 引起的如: Ge<A> 和 Ge<B> ,Guid名相同,所以用FullName

            if (!isAnonymousType && propCache.ContainsKey(key))
            {
                return(propCache[key]);
            }
            else
            {
                bool                isInheritOrm = t.BaseType.Name.StartsWith("OrmBase") || t.BaseType.Name.StartsWith("SimpleOrmBase");
                PropertyInfo[]      pInfo        = isInheritOrm ? t.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly) : t.GetProperties();
                List <PropertyInfo> list         = new List <PropertyInfo>(pInfo.Length);
                try
                {
                    list.AddRange(pInfo);
                    if (!isAnonymousType)
                    {
                        propCache.Set(key, list);
                    }
                }
                catch (Exception err)
                {
                    Log.Write(err, LogType.Error);
                }
                return(list);
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// 获取属性列表
 /// </summary>
 /// <param name="t"></param>
 /// <returns></returns>
 internal static PropertyInfo[] GetPropertyInfo(Type t)
 {
     if (propCache.ContainsKey(t.GUID))
     {
         return(propCache[t.GUID]);
     }
     else
     {
         bool           isInheritOrm = t.BaseType.Name == "OrmBase" || t.BaseType.Name == "SimpleOrmBase";
         PropertyInfo[] pInfo        = isInheritOrm ? t.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly) : t.GetProperties();
         try
         {
             propCache.Set(t.GUID, pInfo);
         }
         catch
         {
         }
         return(pInfo);
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// 获取泛型的参数长度,同时类型修改为普通类型(非泛型按默认方法计算)
        /// </summary>
        public static int GetArgumentLength(ref Type t, out Type[] argTypes)
        {
            string key = t.FullName;

            if (argumentCache.ContainsKey(key))
            {
                argTypes = argumentCache[key];
            }
            else
            {
                int len = 0;

                if (t.IsGenericType)
                {
                    #region MyRegion
                    argTypes = t.GetGenericArguments();
                    len      = argTypes.Length;
                    for (int i = 0; i < argTypes.Length; i++)
                    {
                        if (argTypes[i].IsGenericType && argTypes[i].Name.StartsWith("Nullable"))
                        {
                            argTypes[i] = Nullable.GetUnderlyingType(argTypes[i]);
                        }
                    }
                    #endregion
                }
                else
                {
                    #region 非泛型


                    if (t.Name.EndsWith("[]") || t.Name == "MDataRowCollection" || t.Name == "MDataColumn")
                    {
                        len = 1;
                    }
                    else if (t.Name == "NameValueCollection" || (t.BaseType != null && t.BaseType.Name == "NameValueCollection"))
                    {
                        len = 2;
                    }
                    else if (t.BaseType != null && t.BaseType.Name == "DbParameterCollection")
                    {
                        len = 1;
                    }
                    else
                    {
                        System.Reflection.MethodInfo mi = t.GetMethod("Add");
                        if (mi != null)
                        {
                            len = mi.GetParameters().Length;
                        }
                    }
                    argTypes = new Type[len];
                    for (int i = 0; i < argTypes.Length; i++)
                    {
                        argTypes[i] = typeof(object);
                    }
                    #endregion
                }

                argumentCache.Set(key, argTypes);
            }
            if (t.IsGenericType)
            {
                if (t.Name.StartsWith("Nullable"))
                {
                    t = Nullable.GetUnderlyingType(t);
                }
                else if (t.Name == "IList`1")
                {
                    //List<int> a;typeof(List<int>);
                    t = typeof(List <>).MakeGenericType(argTypes[0]);
                }
                else if (t.Name == "IDictionary`2")
                {
                    t = typeof(Dictionary <,>).MakeGenericType(argTypes[0], argTypes[1]);
                }
            }
            return(argTypes.Length);
        }