示例#1
0
 internal static string GetHashKey(string sourceString)
 {
     try
     {
         if (hashKeyCache.ContainsKey(sourceString))
         {
             return(hashKeyCache[sourceString]);
         }
         else
         {
             if (hashKeyCache.Count > 512)
             {
                 hashKeyCache.Clear();
                 hashKeyCache = new MDictionary <string, string>(64);
             }
             string value = "K" + Math.Abs(sourceString.GetHashCode()) + sourceString.Length;
             hashKeyCache.Add(sourceString, value);
             return(value);
         }
     }
     catch
     {
         return(sourceString);
     }
 }
示例#2
0
        /// <summary>
        /// 判断是否存在指定的属性
        /// </summary>
        /// <param name="searchType"></param>
        /// <param name="pi"></param>
        /// <returns></returns>
        internal static bool ExistsAttr(Type searchType, PropertyInfo pi, FieldInfo fi)
        {
            string key  = (pi != null ? pi.DeclaringType.FullName + pi.Name : fi.DeclaringType.FullName + fi.Name) + searchType.Name;
            int    code = key.GetHashCode();

            if (attrExistsCache.ContainsKey(code))
            {
                return(attrExistsCache[code]);
            }
            object[] items = pi != null?pi.GetCustomAttributes(searchType, true) : fi.GetCustomAttributes(searchType, true);

            if (items != null && items.Length > 0)
            {
                attrExistsCache.Add(code, true);
                return(true);
            }
            attrExistsCache.Add(code, false);
            return(false);
        }
示例#3
0
        /// <summary>
        /// 获取特性列表
        /// </summary>
        private static object[] GetAttributes(Type t, Type searchType, PropertyInfo pi, FieldInfo fi)
        {
            string key = t.GUID.ToString();

            if (searchType != null)
            {
                key += searchType.Name;
            }
            if (pi != null)
            {
                key += pi.Name;
            }
            else if (fi != null)
            {
                key += fi.Name;
            }
            //key = key.GetHashCode().ToString();
            if (attrCache.ContainsKey(key))
            {
                return(attrCache[key]);
            }
            else
            {
                try
                {
                    object[] items = null;
                    if (pi != null)
                    {
                        items = searchType == null?pi.GetCustomAttributes(false) : pi.GetCustomAttributes(searchType, true);
                    }
                    else if (fi != null)
                    {
                        items = searchType == null?fi.GetCustomAttributes(false) : fi.GetCustomAttributes(searchType, true);
                    }
                    else
                    {
                        items = searchType == null?t.GetCustomAttributes(false) : t.GetCustomAttributes(searchType, true);
                    }
                    attrCache.Add(key, items);
                    return(items);
                }
                catch (Exception err)
                {
                    Log.Write(err, LogType.Error);
                }
                return(null);
            }
        }
示例#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.Add(t.GUID, pInfo);
         }
         catch
         {
         }
         return(pInfo);
     }
 }