Ejemplo n.º 1
0
            internal static void RemoveEventHandler <T>(Action <EventRegistrationToken> removeMethod, T handler)
            {
                object instanceKey = WindowsRuntimeMarshal.NativeOrStaticEventRegistrationImpl.GetInstanceKey(removeMethod);

                WindowsRuntimeMarshal.NativeOrStaticEventRegistrationImpl.s_eventCacheRWLock.AcquireReaderLock(-1);
                EventRegistrationToken token;

                try
                {
                    WindowsRuntimeMarshal.NativeOrStaticEventRegistrationImpl.TokenListCount tokenListCount;
                    ConditionalWeakTable <object, WindowsRuntimeMarshal.NativeOrStaticEventRegistrationImpl.EventRegistrationTokenListWithCount> tokenTableNoCreate = WindowsRuntimeMarshal.NativeOrStaticEventRegistrationImpl.GetEventRegistrationTokenTableNoCreate(instanceKey, removeMethod, out tokenListCount);
                    if (tokenTableNoCreate == null)
                    {
                        return;
                    }
                    lock (tokenTableNoCreate)
                    {
                        WindowsRuntimeMarshal.NativeOrStaticEventRegistrationImpl.EventRegistrationTokenListWithCount local_6;
                        object local_7 = tokenTableNoCreate.FindEquivalentKeyUnsafe((object)handler, out local_6);
                        if (local_6 == null)
                        {
                            return;
                        }
                        if (!local_6.Pop(out token))
                        {
                            tokenTableNoCreate.Remove(local_7);
                        }
                    }
                }
                finally
                {
                    WindowsRuntimeMarshal.NativeOrStaticEventRegistrationImpl.s_eventCacheRWLock.ReleaseReaderLock();
                }
                removeMethod(token);
            }
Ejemplo n.º 2
0
 public static TKey FindEquivalentKeyUnsafe <TKey, TValue>(
     this ConditionalWeakTable <TKey, TValue> table,
     TKey key,
     out TValue value
     )
     where TKey : class
     where TValue : class
 {
     return(table.FindEquivalentKeyUnsafe(key, out value));
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Given a key, locate the corresponding value in the ConditionalWeakTable according to value
        /// equality. Will create a new value if the key is not found.
        /// <summary>
        public static TValue GetValueFromEquivalentKey <TKey, TValue>(ConditionalWeakTable <TKey, TValue> table, TKey key, ConditionalWeakTable <TKey, TValue> .CreateValueCallback callback)
            where TKey : class
            where TValue : class
        {
            TValue value;
            TKey   foundKey = table.FindEquivalentKeyUnsafe(key, out value);

            if (foundKey == default(TKey))
            {
                value = callback(key);
                table.Add(key, value);
            }

            return(value);
        }
Ejemplo n.º 4
0
        internal static EventHandler <object> GetValueFromEquivalentKey(
            ConditionalWeakTable <EventHandler, EventHandler <object> > table,
            EventHandler key,
            ConditionalWeakTable <EventHandler, EventHandler <object> > .CreateValueCallback callback)
        {
            EventHandler <object> value;

            // Find the key in the table using a value check rather than an instance check.
            EventHandler existingKey = table.FindEquivalentKeyUnsafe(key, out value);

            if (existingKey == null)
            {
                value = callback(key);
                table.Add(key, value);
            }

            return(value);
        }
Ejemplo n.º 5
0
            internal static void AddEventHandler <T>(Func <T, EventRegistrationToken> addMethod, Action <EventRegistrationToken> removeMethod, T handler)
            {
                object instanceKey           = WindowsRuntimeMarshal.NativeOrStaticEventRegistrationImpl.GetInstanceKey(removeMethod);
                EventRegistrationToken token = addMethod(handler);
                bool flag = false;

                try
                {
                    WindowsRuntimeMarshal.NativeOrStaticEventRegistrationImpl.s_eventCacheRWLock.AcquireReaderLock(-1);
                    try
                    {
                        WindowsRuntimeMarshal.NativeOrStaticEventRegistrationImpl.TokenListCount tokenListCount;
                        ConditionalWeakTable <object, WindowsRuntimeMarshal.NativeOrStaticEventRegistrationImpl.EventRegistrationTokenListWithCount> registrationTokenTable = WindowsRuntimeMarshal.NativeOrStaticEventRegistrationImpl.GetOrCreateEventRegistrationTokenTable(instanceKey, removeMethod, out tokenListCount);
                        lock (registrationTokenTable)
                        {
                            WindowsRuntimeMarshal.NativeOrStaticEventRegistrationImpl.EventRegistrationTokenListWithCount local_3;
                            if (registrationTokenTable.FindEquivalentKeyUnsafe((object)handler, out local_3) == null)
                            {
                                local_3 = new WindowsRuntimeMarshal.NativeOrStaticEventRegistrationImpl.EventRegistrationTokenListWithCount(tokenListCount, token);
                                registrationTokenTable.Add((object)handler, local_3);
                            }
                            else
                            {
                                local_3.Push(token);
                            }
                            flag = true;
                        }
                    }
                    finally
                    {
                        WindowsRuntimeMarshal.NativeOrStaticEventRegistrationImpl.s_eventCacheRWLock.ReleaseReaderLock();
                    }
                }
                catch (Exception ex)
                {
                    if (!flag)
                    {
                        removeMethod(token);
                    }
                    throw;
                }
            }
Ejemplo n.º 6
0
        internal static EventHandler<object> GetValueFromEquivalentKey(
            ConditionalWeakTable<EventHandler, EventHandler<object>> table,
            EventHandler key,
            ConditionalWeakTable<EventHandler, EventHandler<object>>.CreateValueCallback callback)
        {
            EventHandler<object> value;

            // Find the key in the table using a value check rather than an instance check.
            EventHandler existingKey = table.FindEquivalentKeyUnsafe(key, out value);
            if (existingKey == null)
            {
                value = callback(key);
                table.Add(key, value);
            }

            return value;
        }