public static object ValueAs(Type type, string value) { object obj1 = (object)null; if (type == typeof(DateTime)) { return((object)SFStrings.ToDate(value, new DateTime(1900, 1, 1))); } if (type.IsGenericType && (object)type.GetGenericTypeDefinition() == (object)typeof(Nullable <>)) { Type underlyingType = Nullable.GetUnderlyingType(type); Type type1 = type.GetGenericTypeDefinition().MakeGenericType(underlyingType); object obj2 = Convert.ChangeType((object)value, underlyingType); if (obj2 != null) { obj1 = Activator.CreateInstance(type1, new object[1] { obj2 }); } } else { obj1 = Convert.ChangeType((object)value, type); } return(obj1); }
public static void SetObjectFromDictionary <T>(T sourceObject, Dictionary <string, string> values) { Dictionary <string, string> dictionary = new Dictionary <string, string>(); if ((object)sourceObject == null) { return; } foreach (PropertyInfo property in sourceObject.GetType().GetProperties()) { try { string name = property.Name; string str; try { str = values[name]; } catch { str = (string)null; } if (str != null) { if (property.CanWrite) { object obj = property.GetValue((object)sourceObject, (object[])null); if (obj is DateTime) { DateTime date = SFStrings.ToDate(str); property.SetValue((object)sourceObject, (object)date); } else if (obj is bool) { if (str.ToLower() == "true" || str == "1") { property.SetValue((object)sourceObject, (object)true); } else { property.SetValue((object)sourceObject, (object)false); } } else if (!(obj is int)) { if (!(obj is float)) { if (!(obj is Decimal)) { Type type = obj.GetType(); property.SetValue((object)sourceObject, SFClass.ValueAs(type, str)); } } } } } } catch { } } }