private void SetKeyAndObject(CacheKeyAttribute cka, object defaultValue, List <string> cachekeys, MemberInfo mi, object baseObjectValue) { if (defaultValue != baseObjectValue) { cachekeys.Add(KeyName(cka, mi) + ":" + (baseObjectValue != null ? baseObjectValue.ToString() : string.Empty)); } }
private bool IsIgnored(CacheKeyAttribute cka, MemberInfo mi) { if (cka != null && mi.IsDefined(_typeCacheKeyAttr, true)) { return(cka.Ignored); } return(false); }
private static string KeyName(CacheKeyAttribute cka, MemberInfo mi) { if (cka != null && mi.IsDefined(_typeCacheKeyAttr, true)) { return(cka.KeyName); } return(mi.Name); }
protected string CreateKey <T>() { CacheKeyAttribute cacheKeyAttribute = (CacheKeyAttribute)typeof(T).GetCustomAttributes(typeof(CacheKeyAttribute), false).Single(); string key = cacheKeyAttribute.Key.Replace('.', '-'); //string key = typeof(T).FullName.Replace(".", "_"); return(key); }
private CacheKeyAttribute GetFirstCacheKeyAttribute(MemberInfo mi) { object[] ca = mi.GetCustomAttributes(_typeCacheKeyAttr, true); if (ca != null) { for (int i = 0; i < ca.Length; i++) { CacheKeyAttribute cka = ca[i] as CacheKeyAttribute; if (cka != null) { return(cka); } } } return(null); }
protected void EnsureInitialized() { _cacheKeyInforamtion.AddIfDoesntContainFunc(GetType(), () => { List <CacheKeyPropertyInfo> info = new List <CacheKeyPropertyInfo>(); PropertyInfo[] properties = GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public); foreach (PropertyInfo pi in properties) { if (!pi.IsDefined(_typeObsoleteAttr, true)) { CacheKeyAttribute cka = GetFirstCacheKeyAttribute(pi); if (pi.CanRead && !IsIgnored(cka, pi) && cka != null) { info.Add(new CacheKeyPropertyInfo() { CacheKeyAttribute = cka, PropertyInfo = pi, DefaultValue = cka.DefaultValue }); } } } FieldInfo[] fields = GetType().GetFields(BindingFlags.Instance | BindingFlags.Public); foreach (FieldInfo fi in fields) { if (!fi.IsDefined(_typeObsoleteAttr, true)) { CacheKeyAttribute cka = GetFirstCacheKeyAttribute(fi); if (fi.IsPublic && !IsIgnored(cka, fi) && cka != null) { info.Add(new CacheKeyPropertyInfo() { CacheKeyAttribute = cka, FieldInfo = fi, DefaultValue = cka.DefaultValue }); } } } return(info); }); }