public T Restore <T>(DogEngine.IStorage storage) where T : class { var restoredObject = Activator.CreateInstance(typeof(T)); foreach (var prop in GetProperties(typeof(T))) { RestoreProperty(prop, restoredObject, storage); } return((T)restoredObject); }
public void Persist(object objectToPersist, DogEngine.IStorage storage) { if (objectToPersist == null) { throw new ArgumentNullException("objectToPersist", "Unable to persist Null object"); } foreach (var prop in GetProperties(objectToPersist.GetType())) { var propValue = prop.GetValue(objectToPersist, null); PersistProperty(prop, propValue, storage); } }
private void RestoreProperty(PropertyInfo prop, object objToRead, DogEngine.IStorage storage) { if (storage.Exists(prop.Name)) { try { var propValue = storage.GetByName(prop.Name); prop.SetValue(objToRead, GetConvertedValue(prop, propValue), null); } catch (Exception ex) { //TODO: add log if unable to restore property for any reason } } }
private void PersistProperty(PropertyInfo prop, object propValue, DogEngine.IStorage storage) { var toString = (string)Convert.ChangeType(propValue, typeof(string)); storage.StoreByName(prop.Name, toString); }