Пример #1
0
 public static TEntity AddOrUpdate <TKey, TEntity>(this IAtomicEntityWriter <TKey, TEntity> self, TKey key, Func <TEntity> addFactory, Action <TEntity> update, AddOrUpdateHint hint = AddOrUpdateHint.ProbablyExists)
 {
     return(self.AddOrUpdate(key, addFactory, entity =>
     {
         update(entity);
         return entity;
     }, hint));
 }
Пример #2
0
 public static TEntity UpdateOrThrow <TKey, TEntity>(this IAtomicEntityWriter <TKey, TEntity> self, TKey key, Action <TEntity> change)
 {
     return(self.AddOrUpdate(key, () =>
     {
         var txt = String.Format("Failed to load '{0}' with key '{1}'.", typeof(TEntity).Name, key);
         throw new InvalidOperationException(txt);
     }, change, AddOrUpdateHint.ProbablyExists));
 }
Пример #3
0
 public static TEntity Add <TKey, TEntity>(this IAtomicEntityWriter <TKey, TEntity> self, TKey key, TEntity newEntity)
 {
     return(self.AddOrUpdate(key, newEntity, e =>
     {
         var txt = String.Format("Entity '{0}' with key '{1}' should not exist.", typeof(TEntity).Name, key);
         throw new InvalidOperationException(txt);
     }, AddOrUpdateHint.ProbablyDoesNotExist));
 }
Пример #4
0
 public static TEntity AddOrUpdate <TKey, TEntity>(this IAtomicEntityWriter <TKey, TEntity> self, TKey key, TEntity newView, Action <TEntity> updateViewFactory, AddOrUpdateHint hint = AddOrUpdateHint.ProbablyExists)
 {
     return(self.AddOrUpdate(key, () => newView, view =>
     {
         updateViewFactory(view);
         return view;
     }, hint));
 }
Пример #5
0
 public static TView UpdateEnforcingNew <TKey, TView>(this IAtomicEntityWriter <TKey, TView> self, TKey key,
                                                      Action <TView> update, AddOrUpdateHint hint = AddOrUpdateHint.ProbablyExists)
     where TView : new()
 {
     return(self.AddOrUpdate(key, () =>
     {
         var view = new TView();
         update(view);
         return view;
     }, v =>
     {
         update(v);
         return v;
     }, hint));
 }
 public TView AddOrUpdate(TKey key, Func <TView> addFactory, Func <TView, TView> update,
                          AddOrUpdateHint hint = AddOrUpdateHint.ProbablyExists)
 {
     return(_inner.AddOrUpdate(key, addFactory, update, hint));
 }