public static void SetProperties(object target, bool throwIfMissingRequiredProperties, bool reload) { Type targetType = target.GetType(); PropertyInfo[] properties = targetType.GetProperties(); foreach (PropertyInfo property in properties) { if (property.CanWrite) { string propertyValueFromConfig = GetValue(targetType.Name + "." + property.Name, reload); if (string.IsNullOrEmpty(propertyValueFromConfig)) { propertyValueFromConfig = GetValue(property.Name); } if (!string.IsNullOrEmpty(propertyValueFromConfig)) { property.SetValue(target, propertyValueFromConfig, null); } } } if (throwIfMissingRequiredProperties) { if (targetType.GetInterface("IHasRequiredProperties") != null) { DefaultConfiguration.CheckRequiredProperties((IHasRequiredProperties)target); } } }
/// <summary> /// Checks the properties named in the RequiredProperties property of the specified /// IHasRequiredProperties object ensuring that each has been set. This method will /// throw an error if any required property is null or an empty string. /// </summary> /// <param name="toBeValidated">The IHasRequiredProperties implementation to check.</param> public static void RequiredProperties(IHasRequiredProperties toBeValidated) { DefaultConfiguration.CheckRequiredProperties(toBeValidated); }