public void Populate(Dictionary <string, object> record) { Dictionary <string, string> map = GetTableMap(); Type type = GetType(); string column; object value; Type propertyType; foreach (string key in map.Keys) { PropertyInfo property = type.GetProperty(key); column = map[key]; if (!record.ContainsKey(column)) { continue; } value = record[column]; propertyType = property.PropertyType; if (propertyType.IsGenericType && propertyType.GetGenericTypeDefinition() == typeof(Nullable <>)) { propertyType = Nullable.GetUnderlyingType(propertyType); } if (propertyType == typeof(RestDateTime)) { value = new RestDateTime(RestDatabase.DateTimeFromTimestamp((long)value)); } else if (propertyType.IsEnum) { value = Enum.Parse(propertyType, value.ToString()); } property.SetValue(this, value); } }
protected virtual void SetDefaults() { CreatedAt = new RestDateTime(DateTime.UtcNow); UpdatedAt = CreatedAt; }