internal EventRegistrationTokenListWithCount(TokenListCount tokenListCount, EventRegistrationToken token) { _tokenListCount = tokenListCount; _tokenListCount.Inc(); _tokenList = new EventRegistrationTokenList(token); }
internal static void AddEventHandler <T>(Func <T, EventRegistrationToken> addMethod, Action <EventRegistrationToken> removeMethod, T handler) { Debug.Assert(addMethod != null); Debug.Assert(removeMethod != null); // Add the method, and make a note of the token -> delegate mapping. object instance = removeMethod.Target; #if !RHTESTCL Debug.Assert(instance != null && !(instance is __ComObject)); #endif System.Collections.Generic.Internal.Dictionary <object, EventRegistrationTokenList> registrationTokens = GetEventRegistrationTokenTable(instance, removeMethod); EventRegistrationToken token = addMethod(handler); try { registrationTokens.LockAcquire(); EventRegistrationTokenList tokens; if (!registrationTokens.TryGetValue(handler, out tokens)) { tokens = new EventRegistrationTokenList(token); registrationTokens[handler] = tokens; } else { bool needCopy = tokens.Push(token); // You need to copy back this list into the dictionary (so that you don't lose change outside dictionary) if (needCopy) { registrationTokens[handler] = tokens; } } #if false BCLDebug.Log("INTEROP", "[WinRT_Eventing] Event subscribed for managed instance = " + instance + ", handler = " + handler + "\n"); #endif } finally { registrationTokens.LockRelease(); } }
internal EventRegistrationTokenList(EventRegistrationTokenList list) { firstToken = list.firstToken; restTokens = list.restTokens; }