Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- internal static class TransactionExtensions
- {
- /// <summary>
- /// The get transaction for type.
- /// </summary>
- private static readonly ConcurrentDictionary<Type, Func<ITransaction, Transaction>> GetTransactionForType =
- new ConcurrentDictionary<Type, Func<ITransaction, Transaction>>();
- public static Transaction GetTransaction(this ITransaction tx)
- {
- // Note: this is ugly, but in order to co-operate with System.Fabric.Data's transactions, this is the cleanest way.
- var getTransaction = GetTransactionForType.GetOrAdd(
- tx.GetType(),
- type =>
- {
- var property = type.GetProperty("Transaction");
- var getMethod = property.GetGetMethod();
- return ttx => (Transaction)getMethod.Invoke(ttx, new object[0]);
- });
- return getTransaction(tx);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement