public static List <T> GetAttributeList <T>(Type type) where T : class { List <T> result = new List <T>(); foreach (var attribute in type.GetCustomAttributes()) { T item = attribute as T; if (item != null) { result.Add(item); } } foreach (var propertyInfo in type.GetProperties()) { foreach (var attribute in propertyInfo.GetCustomAttributes()) { T item = attribute as T; if (item != null) { IPropertyInfoInit propertyInfoInit = item as IPropertyInfoInit; if (propertyInfoInit != null) { propertyInfoInit.Init(propertyInfo); } result.Add(item); } } } return(result); }
public static List <IAddViewData> GetAddViewDataList(Type type) { List <IAddViewData> result = new List <IAddViewData>(); foreach (var attribute in type.GetCustomAttributes()) { IAddViewData addViewData = attribute as IAddViewData; if (addViewData != null) { result.Add(addViewData); } } foreach (var propertyInfo in type.GetProperties()) { foreach (var attribute in propertyInfo.GetCustomAttributes()) { IAddViewData addViewData = attribute as IAddViewData; if (addViewData != null) { IPropertyInfoInit propertyInfoInit = addViewData as IPropertyInfoInit; if (propertyInfoInit != null) { propertyInfoInit.Init(propertyInfo); } result.Add(addViewData); } } } return(result); }
public static List <T> GetPropertyAttributeList <T>(PropertyInfo propertyInfo) where T : class { List <T> result = new List <T>(); foreach (var attribute in propertyInfo.GetCustomAttributes()) { T targetType = attribute as T; if (targetType != null) { IPropertyInfoInit propertyInfoInit = targetType as IPropertyInfoInit; if (propertyInfoInit != null) { propertyInfoInit.Init(propertyInfo); } result.Add(targetType); } } return(result); }