public void TryPopulateModel(object model, IParameterCollection parameterCollection) { if (parameterCollection == null) { throw new ArgumentNullException("parameterCollection"); } var errors = new Dictionary <string, Exception>(); ICachedType type = PropertyProvider.Get(model.GetType()); foreach (IParameter parameter in parameterCollection) { try { object value = parameter.Value; type.SetConvertedValue(model, parameter.Name, value); } catch (Exception err) { errors[parameter.Name] = err; } } if (errors.Count != 0) { throw new PropertyException(errors); } }
/// <summary> /// Assign properties in the specified object. /// </summary> /// <param name="instance">Object to fill.</param> /// <param name="parameters">Contains all parameters that should be assigned to the properties.</param> /// <exception cref="PropertyException">Properties was not found or value could not be converted.</exception> /// <exception cref="ArgumentNullException">Any parameter is <c>null</c>.</exception> public static void Assign(object instance, IParameterCollection parameters) { if (instance == null) { throw new ArgumentNullException("instance"); } if (parameters == null) { throw new ArgumentNullException("parameters"); } var errors = new Dictionary <string, Exception>(); ICachedType type = PropertyProvider.Get(instance.GetType()); foreach (IParameter parameter in parameters) { try { object value = parameter.Value; if (_handler != null && !_handler(instance, parameter.Name, ref value)) { continue; } type.SetConvertedValue(instance, parameter.Name, value); } catch (Exception err) { errors[parameter.Name] = err; } } if (errors.Count != 0) { throw new PropertyException(errors); } }