private void Apply(GeneralOptions options, IDictionary properties) { if (options == null) { throw new ArgumentNullException("options"); } if (properties == null) { throw new ArgumentNullException("properties"); } foreach (var propInfo in options.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public)) { var propNameAttrib = GetAttribute <PropertyNameAttribute>(propInfo); var defaultValueAttrib = GetAttribute <DefaultValueAttribute>(propInfo); if (propNameAttrib == null || defaultValueAttrib == null) { continue; } var value = propInfo.GetValue(options, null); if ((value == null && defaultValueAttrib.Value == null) || (value != null && value.Equals(defaultValueAttrib.Value))) { continue; } properties[propNameAttrib.Name] = value; } if (options.ExtraProperties != null) { foreach (var key in options.ExtraProperties.Keys) { properties[key] = options.ExtraProperties[key]; } } }
private void SetPropertiesToDefaultValues(GeneralOptions options) { if (options == null) { throw new ArgumentNullException("options"); } foreach (var propInfo in options.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public)) { var propNameAttrib = GetAttribute <PropertyNameAttribute>(propInfo); var defaultValueAttrib = GetAttribute <DefaultValueAttribute>(propInfo); if (propNameAttrib == null || defaultValueAttrib == null) { continue; } propInfo.SetValue(options, defaultValueAttrib.Value, null); } }