protected virtual void Initialize(object component, IEnumerable<KeyValuePair<string, object>> values, IPopulateComponentCallback callback = null, IServiceProvider serviceProvider = null) { if (component == null) throw new ArgumentNullException("component"); // $NON-NLS-1 if (values == null) return; serviceProvider = serviceProvider ?? ServiceProvider.Null; callback = callback ?? PopulateComponentCallback.Default; PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(component); foreach (var kvp in values) { PropertyDescriptor pd = properties.Find(kvp.Key, true); if (pd == null) { callback.Missing(serviceProvider, kvp.Key); continue; } object defaultValue = kvp.Value; try { if (defaultValue == null || pd.PropertyType.IsInstanceOfType(defaultValue)) { } else { defaultValue = pd.Converter.ConvertFrom(defaultValue); } pd.SetValue(component, defaultValue); } catch (Exception ex) { callback.ConversionError(serviceProvider, pd, defaultValue, ex); } } }