protected virtual void Initialize(object component, IEnumerable <KeyValuePair <string, object> > values, IServiceProvider serviceProvider = null) { if (component == null) { throw new ArgumentNullException(nameof(component)); } if (values == null) { return; } serviceProvider = serviceProvider ?? ServiceProvider.Null; var exceptionHandler = serviceProvider.GetServiceOrDefault( Activation.IgnoreErrors ); var props = Template.GetPropertyCache(component); foreach (var kvp in values.Distinct(KeyComparer)) { PropertyInfo pd = props.GetValueOrDefault(kvp.Key); if (pd == null) { exceptionHandler(null, RuntimeFailure.PropertyMissing(kvp.Key)); continue; } if (pd.SetMethod == null || !pd.SetMethod.IsPublic) { var dest = pd.GetValue(component); Template.DefaultCopyContent(kvp.Value, dest); continue; } object defaultValue = kvp.Value; try { // Conversion from string var text = defaultValue as string; if (text != null) { defaultValue = Activation.FromText(pd.PropertyType, text); } pd.SetValue(component, defaultValue); } catch (Exception ex) { exceptionHandler(null, ex); } } }