public static string GetClassName <T>(this T t) where T : class { string name; if (MyCache.GetCache($"Class{typeof(T).Name}") == null) { Type type = typeof(T); name = type.Name; NameAttribute nameAttribute = type.GetCustomAttribute(typeof(NameAttribute), true) as NameAttribute; if (nameAttribute != null) { name = nameAttribute.Name; } MyCache.SetCache($"Class{typeof(T).Name}", name); } else { name = MyCache.GetCache($"Class{typeof(T).Name}").ToString(); } return(name); }
public static string GetPropName(this PropertyInfo propertyInfo) { string name; if (MyCache.GetCache($"propertyInfo{propertyInfo.Name}") == null) { name = propertyInfo.Name; Type attributeType = typeof(NameAttribute); NameAttribute nameAttribute = propertyInfo.GetCustomAttribute(attributeType, true) as NameAttribute; if (nameAttribute != null) { name = nameAttribute.Name; } MyCache.SetCache($"propertyInfo{propertyInfo.Name}", name); } else { name = MyCache.GetCache($"propertyInfo{propertyInfo.Name}").ToString(); } return(name); }