Exemple #1
0
 public void SetProperties(OptimizerSettingsPropertyList propertyList)
 {
     foreach (var propertyInfo in GetType().GetProperties().Where(p => p.CanRead && p.CanWrite))
     {
         IEnumerable <Attribute> customAttributes = propertyInfo.GetCustomAttributes(typeof(TypeConverterAttribute));
         TypeConverter           typeConverter;
         if (customAttributes.Count() > 0)
         {
             typeConverter = (TypeConverter)Activator.CreateInstance(Type.GetType(((TypeConverterAttribute)customAttributes.First <Attribute>()).ConverterTypeName));
         }
         else
         {
             typeConverter = TypeDescriptor.GetConverter(propertyInfo.PropertyType);
         }
         if (typeConverter != null && typeConverter.CanConvertFrom(typeof(string)))
         {
             string value = propertyList.GetValue(propertyInfo.Name);
             if (value != null && typeConverter.IsValid(value))
             {
                 propertyInfo.SetValue(this, typeConverter.ConvertFromInvariantString(value), null);
             }
         }
     }
 }