/// <summary> /// Creates a configuration for a given object by using its properties and the <see cref="ConfigurationAttribute"/>. /// </summary> /// <param name="BoundObject">The object for which a set of configuration entries should be created.</param> /// <returns>An instance of the <see cref="GenericConfiguration"/> class that is bound the the given object.</returns> public static GenericConfiguration CreateFor(Object BoundObject) { GenericConfiguration config = new GenericConfiguration(); config.BoundObject = BoundObject; Type t = GetDirectType(BoundObject); foreach (PropertyInfo prop in t.GetProperties()) { config.AddByPropertyWithAttribute(BoundObject, prop); } return config; }
/// <summary> /// Creates a configuration for a given type. The type must be a class. /// </summary> /// <param name="type">The type that defines the configuration entries.</param> /// <returns>An instance of the <see cref="GenericConfiguration"/> class that contains the configuration entries as defined by the given type.</returns> /// <exception cref="System.ArgumentException">Thrown when <paramref name="type"/> is not a class type.</exception> public static GenericConfiguration CreateFor(Type type) { if (!type.IsClass) throw new ArgumentException("The passed type must be a class.", "type"); GenericConfiguration config = new GenericConfiguration(); foreach (PropertyInfo prop in type.GetProperties()) { config.AddByPropertyWithAttribute(null, prop); } return config; }