public static void SetPropertyValue(this object obj, PropertyInfo propertyInfo, object valueToSet) { try { var newType = ExtensibleTypeConverter.ChangeType(valueToSet, propertyInfo.PropertyType); if (propertyInfo.CanWrite) { propertyInfo.SetValue(obj, newType); } } catch (Exception) { } }
public static IDictionary <string, string> GetPropertyValues(this object activated, Func <PropertyInfo, bool> condition) { var propertiesFilered = activated.GetType().GetPropertiesFiltered(condition).ToList(); var parameters = new Dictionary <string, string>(); foreach (var property in propertiesFilered) { if (!property.CanRead) { continue; } var key = property.Name; var val = (string)ExtensibleTypeConverter.ChangeType(property.GetValue(activated), typeof(string)); parameters.Add(key, val); } return(parameters); }