public static bool TryGetCurrentData([NotNullWhen(true)] out ContextData?currentData) { currentData = null; ContextKey?contextKey = s_currentTransaction.Value; if (contextKey == null) { return(false); } else { return(s_contextDataTable.TryGetValue(contextKey, out currentData)); } }
public static void ClearCurrentData(ContextKey?contextKey, bool removeContextData) { // Get the current ambient CallContext. ContextKey?key = s_currentTransaction.Value; if (contextKey != null || key != null) { // removeContextData flag is used for perf optimization to avoid removing from the table in certain nested TransactionScope usage. if (removeContextData) { // if context key is passed in remove that from the contextDataTable, otherwise remove the default context key. s_contextDataTable.Remove(contextKey ?? key !); } if (key != null) { s_currentTransaction.Value = null; } } }