示例#1
0
        /// <summary>
        /// Implements copy functionalty for GetAsFrozenCore and GetCurrentValueAsFrozenCore
        /// Timeline does not need to override CloneCore and CloneCurrentValueCore.
        /// </summary>
        /// <param name="sourceTimeline"></param>
        private void CopyCommon(Timeline sourceTimeline)
        {
            // When creating a frozen copy of a Timeline we want to copy the
            // event handlers. This is for two reasons
            //
            //   1.) Internally when creating a clock tree we use
            //       a frozen copy of the timing tree.  If that frozen
            //       copy does not preserve the event handlers then
            //       any callbacks registered on the Timelines will be lost.
            //
            //   2.) GetAsFrozen and GetCurrentValueAsFrozen don't always clone.
            //       If any object in the tree is frozen it'll simply return it.
            //       If we did not copy the event handlers GetAsFrozen
            //       would return different results depending on whether a
            //       Timeline was frozen before the call.
            //
            //
            // The other two clone methods make unfrozen clones, so it's consisent
            // to not copy the event handlers for those methods.  Cloning an object
            // is basically the only way to get a 'fresh' copy without event handlers
            // attached.  If someone wants a frozen clone they probably want an exact
            // copy of the original.

            EventHandlersStore sourceStore = EventHandlersStoreField.GetValue(sourceTimeline);

            if (sourceStore != null)
            {
                Debug.Assert(sourceStore.Count > 0);
                EventHandlersStoreField.SetValue(this, new EventHandlersStore(sourceStore));
            }
        }
示例#2
0
        /// <summary>
        /// Adds a delegate to the list of event handlers on this object.
        /// </summary>
        /// <param name="key">
        /// A unique identifier for the event handler.
        /// </param>
        /// <param name="handler">The delegate to add.</param>
        private void AddEventHandler(EventPrivateKey key, Delegate handler)
        {
            WritePreamble();

            EventHandlersStore store = EventHandlersStoreField.GetValue(this);

            if (store == null)
            {
                store = new EventHandlersStore();
                EventHandlersStoreField.SetValue(this, store);
            }

            store.Add(key, handler);
            WritePostscript();
        }
示例#3
0
        /// <summary>
        /// Removes a delegate from the list of event handlers on this object.
        /// </summary>
        /// <param name="key">
        /// A unique identifier for the event handler.
        /// </param>
        /// <param name="handler">The delegate to remove.</param>
        private void RemoveEventHandler(EventPrivateKey key, Delegate handler)
        {
            WritePreamble();

            EventHandlersStore store = EventHandlersStoreField.GetValue(this);
            if (store != null)
            {
                store.Remove(key, handler);
                if (store.Count == 0)
                {
                    // last event handler was removed -- throw away underlying EventHandlersStore
                    EventHandlersStoreField.ClearValue(this);
                }

                WritePostscript();
            }
        }