public void FillCustomExportParameter(object obj) { PropertyInfo[] propertyInfos = obj.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly); foreach (PropertyInfo propertyInfo in propertyInfos) { CustomExportAttribute customExportAttribute = propertyInfo.GetCustomAttribute <CustomExportAttribute>(); if (customExportAttribute != null) { string displayName = string.IsNullOrEmpty(customExportAttribute.DisplayName) ? propertyInfo.Name : customExportAttribute.DisplayName; if (customExportAttribute.AddType) { displayName = string.Format("{0}({1})", obj.GetType().Name, displayName); } if (ContainsParameter(displayName)) { try { propertyInfo.SetValue(obj, GetValue(displayName).Value, new object[0]); } catch (Exception) { // ignored } } } } }
public static IDictionary <string, PropertyInfo> GetCustomPossibleProperties(Type[] possibleTypes) { Dictionary <string, PropertyInfo> result = new Dictionary <string, PropertyInfo>(); foreach (Type possibleType in possibleTypes) { PropertyInfo[] propertyInfos = possibleType.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly); foreach (PropertyInfo propertyInfo in propertyInfos) { CustomExportAttribute customExportAttribute = propertyInfo.GetCustomAttribute <CustomExportAttribute>(); if (customExportAttribute != null) { string displayName = string.IsNullOrEmpty(customExportAttribute.DisplayName) ? propertyInfo.Name : customExportAttribute.DisplayName; if (customExportAttribute.AddType) { displayName = string.Format("{0}({1})", possibleType.Name, displayName); } result[displayName] = propertyInfo; } } } return(result); }
public void AddCustomExportParameter(object obj) { PropertyInfo[] propertyInfos = obj.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly); foreach (PropertyInfo propertyInfo in propertyInfos) { CustomExportAttribute customExportAttribute = propertyInfo.GetCustomAttribute <CustomExportAttribute>(); if (customExportAttribute != null) { string displayName = string.IsNullOrEmpty(customExportAttribute.DisplayName) ? propertyInfo.Name : customExportAttribute.DisplayName; if (customExportAttribute.AddType) { displayName = string.Format("{0}({1})", obj.GetType().Name, displayName); } AddParameter(displayName, new Parameter { Type = propertyInfo.PropertyType, Value = propertyInfo.GetValue(obj, new object[0]) }); } } }