Advertisement
Guest User

Untitled

a guest
Jul 5th, 2015
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. internal static class TransactionExtensions
  2. {
  3. /// <summary>
  4. /// The get transaction for type.
  5. /// </summary>
  6. private static readonly ConcurrentDictionary<Type, Func<ITransaction, Transaction>> GetTransactionForType =
  7. new ConcurrentDictionary<Type, Func<ITransaction, Transaction>>();
  8.  
  9. public static Transaction GetTransaction(this ITransaction tx)
  10. {
  11. // Note: this is ugly, but in order to co-operate with System.Fabric.Data's transactions, this is the cleanest way.
  12. var getTransaction = GetTransactionForType.GetOrAdd(
  13. tx.GetType(),
  14. type =>
  15. {
  16. var property = type.GetProperty("Transaction");
  17. var getMethod = property.GetGetMethod();
  18. return ttx => (Transaction)getMethod.Invoke(ttx, new object[0]);
  19. });
  20.  
  21. return getTransaction(tx);
  22. }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement