Пример #1
0
 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
                 }
             }
         }
     }
 }
Пример #2
0
        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);
        }
Пример #3
0
 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])
             });
         }
     }
 }