Esempio n. 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));
            }
        }
Esempio n. 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();
        }