File: System\Windows\Media\Animation\Generated\SingleKeyFrameCollection.cs
Web Access
Project: src\src\Microsoft.DotNet.Wpf\src\PresentationCore\PresentationCore.csproj (PresentationCore)
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
 
//
//
// This file was generated, please do not edit it directly.
//
// Please see MilCodeGen.html for more information.
//
 
using MS.Internal;
 
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Windows.Media.Animation;
using System.Windows.Media.Media3D;
 
namespace System.Windows.Media.Animation
{
    /// <summary>
    /// This collection is used in conjunction with a KeyFrameSingleAnimation
    /// to animate a Single property value along a set of key frames.
    /// </summary>
    public class SingleKeyFrameCollection : Freezable, IList
    {
        #region Data
 
        private List<SingleKeyFrame> _keyFrames;
        private static SingleKeyFrameCollection s_emptyCollection;
 
        #endregion
 
        #region Constructors
 
        /// <Summary>
        /// Creates a new SingleKeyFrameCollection.
        /// </Summary>
        public SingleKeyFrameCollection()
            : base()
        {
            _keyFrames = new List< SingleKeyFrame>(2);
        }
 
        #endregion
 
        #region Static Methods
 
        /// <summary>
        /// An empty SingleKeyFrameCollection.
        /// </summary>
        public static SingleKeyFrameCollection Empty
        {
            get
            {
                if (s_emptyCollection == null)
                {
                    SingleKeyFrameCollection emptyCollection = new SingleKeyFrameCollection();
 
                    emptyCollection._keyFrames = new List< SingleKeyFrame>(0);
                    emptyCollection.Freeze();
 
                    s_emptyCollection = emptyCollection;
                }
 
                return s_emptyCollection;
            }
        }
 
        #endregion
 
        #region Freezable
 
        /// <summary>
        /// Creates a freezable copy of this SingleKeyFrameCollection.
        /// </summary>
        /// <returns>The copy</returns>
        public new SingleKeyFrameCollection Clone()
        {
            return (SingleKeyFrameCollection)base.Clone();
        }
 
        /// <summary>
        /// Implementation of <see cref="System.Windows.Freezable.CreateInstanceCore">Freezable.CreateInstanceCore</see>.
        /// </summary>
        /// <returns>The new Freezable.</returns>
        protected override Freezable CreateInstanceCore()
        {
            return new SingleKeyFrameCollection();
        }
 
        /// <summary>
        /// Implementation of <see cref="System.Windows.Freezable.CloneCore(System.Windows.Freezable)">Freezable.CloneCore</see>.
        /// </summary>
        protected override void CloneCore(Freezable sourceFreezable)
        {
            SingleKeyFrameCollection sourceCollection = (SingleKeyFrameCollection) sourceFreezable;
            base.CloneCore(sourceFreezable);
 
            int count = sourceCollection._keyFrames.Count;
 
            _keyFrames = new List< SingleKeyFrame>(count);
 
            for (int i = 0; i < count; i++)
            {
                SingleKeyFrame keyFrame = (SingleKeyFrame)sourceCollection._keyFrames[i].Clone();
                _keyFrames.Add(keyFrame);
                OnFreezablePropertyChanged(null, keyFrame);
            }
        }
 
 
        /// <summary>
        /// Implementation of <see cref="System.Windows.Freezable.CloneCurrentValueCore(System.Windows.Freezable)">Freezable.CloneCurrentValueCore</see>.
        /// </summary>
        protected override void CloneCurrentValueCore(Freezable sourceFreezable)
        {
            SingleKeyFrameCollection sourceCollection = (SingleKeyFrameCollection) sourceFreezable;
            base.CloneCurrentValueCore(sourceFreezable);
 
            int count = sourceCollection._keyFrames.Count;
 
            _keyFrames = new List< SingleKeyFrame>(count);
 
            for (int i = 0; i < count; i++)
            {
                SingleKeyFrame keyFrame = (SingleKeyFrame)sourceCollection._keyFrames[i].CloneCurrentValue();
                _keyFrames.Add(keyFrame);
                OnFreezablePropertyChanged(null, keyFrame);
            }
        }
 
 
        /// <summary>
        /// Implementation of <see cref="System.Windows.Freezable.GetAsFrozenCore(System.Windows.Freezable)">Freezable.GetAsFrozenCore</see>.
        /// </summary>
        protected override void GetAsFrozenCore(Freezable sourceFreezable)
        {
            SingleKeyFrameCollection sourceCollection = (SingleKeyFrameCollection) sourceFreezable;
            base.GetAsFrozenCore(sourceFreezable);
 
            int count = sourceCollection._keyFrames.Count;
 
            _keyFrames = new List< SingleKeyFrame>(count);
 
            for (int i = 0; i < count; i++)
            {
                SingleKeyFrame keyFrame = (SingleKeyFrame)sourceCollection._keyFrames[i].GetAsFrozen();
                _keyFrames.Add(keyFrame);
                OnFreezablePropertyChanged(null, keyFrame);
            }
        }
 
 
        /// <summary>
        /// Implementation of <see cref="System.Windows.Freezable.GetCurrentValueAsFrozenCore(System.Windows.Freezable)">Freezable.GetCurrentValueAsFrozenCore</see>.
        /// </summary>
        protected override void GetCurrentValueAsFrozenCore(Freezable sourceFreezable)
        {
            SingleKeyFrameCollection sourceCollection = (SingleKeyFrameCollection) sourceFreezable;
            base.GetCurrentValueAsFrozenCore(sourceFreezable);
 
            int count = sourceCollection._keyFrames.Count;
 
            _keyFrames = new List< SingleKeyFrame>(count);
 
            for (int i = 0; i < count; i++)
            {
                SingleKeyFrame keyFrame = (SingleKeyFrame)sourceCollection._keyFrames[i].GetCurrentValueAsFrozen();
                _keyFrames.Add(keyFrame);
                OnFreezablePropertyChanged(null, keyFrame);
            }
        }
 
        /// <summary>
        ///
        /// </summary>
        protected override bool FreezeCore(bool isChecking)
        {
            bool canFreeze = base.FreezeCore(isChecking);
 
            for (int i = 0; i < _keyFrames.Count && canFreeze; i++)
            {
                canFreeze &= Freezable.Freeze(_keyFrames[i], isChecking);
            }
 
            return canFreeze;
        }
 
        #endregion
 
        #region IEnumerable
 
        /// <summary>
        /// Returns an enumerator of the SingleKeyFrames in the collection.
        /// </summary>
        public IEnumerator GetEnumerator()
        {
            ReadPreamble();
 
            return _keyFrames.GetEnumerator();
        }
 
        #endregion
 
        #region ICollection
 
        /// <summary>
        /// Returns the number of SingleKeyFrames in the collection.
        /// </summary>
        public int Count
        {
            get
            {
                ReadPreamble();
 
                return _keyFrames.Count;
            }
        }
 
        /// <summary>
        /// See <see cref="System.Collections.ICollection.IsSynchronized">ICollection.IsSynchronized</see>.
        /// </summary>
        public bool IsSynchronized
        {
            get
            {
                ReadPreamble();
 
                return (IsFrozen || Dispatcher != null);
            }
        }
 
        /// <summary>
        /// See <see cref="System.Collections.ICollection.SyncRoot">ICollection.SyncRoot</see>.
        /// </summary>
        public object SyncRoot
        {
            get
            {
                ReadPreamble();
 
                return ((ICollection)_keyFrames).SyncRoot;
            }
        }
 
        /// <summary>
        /// Copies all of the SingleKeyFrames in the collection to an
        /// array.
        /// </summary>
        void ICollection.CopyTo(Array array, int index)
        {
            ReadPreamble();
 
            ((ICollection)_keyFrames).CopyTo(array, index);
        }
 
        /// <summary>
        /// Copies all of the SingleKeyFrames in the collection to an
        /// array of SingleKeyFrames.
        /// </summary>
        public void CopyTo(SingleKeyFrame[] array, int index)
        {
            ReadPreamble();
 
            _keyFrames.CopyTo(array, index);
        }
 
        #endregion
 
        #region IList
 
        /// <summary>
        /// Adds a SingleKeyFrame to the collection.
        /// </summary>
        int IList.Add(object keyFrame)
        {
            return Add((SingleKeyFrame)keyFrame);
        }
 
        /// <summary>
        /// Adds a SingleKeyFrame to the collection.
        /// </summary>
        public int Add(SingleKeyFrame keyFrame)
        {
            ArgumentNullException.ThrowIfNull(keyFrame);
 
            WritePreamble();
 
            OnFreezablePropertyChanged(null, keyFrame);
            _keyFrames.Add(keyFrame);
 
            WritePostscript();
 
            return _keyFrames.Count - 1;
        }
 
        /// <summary>
        /// Removes all SingleKeyFrames from the collection.
        /// </summary>
        public void Clear()
        {
            WritePreamble();
 
            if (_keyFrames.Count > 0)
            {            
                for (int i = 0; i < _keyFrames.Count; i++)
                {
                    OnFreezablePropertyChanged(_keyFrames[i], null);
                }
 
                _keyFrames.Clear();
 
                WritePostscript();
            }
        }
 
        /// <summary>
        /// Returns true of the collection contains the given SingleKeyFrame.
        /// </summary>
        bool IList.Contains(object keyFrame)
        {
            return Contains((SingleKeyFrame)keyFrame);
        }
 
        /// <summary>
        /// Returns true of the collection contains the given SingleKeyFrame.
        /// </summary>
        public bool Contains(SingleKeyFrame keyFrame)
        {
            ReadPreamble();
 
            return _keyFrames.Contains(keyFrame);
        }
 
        /// <summary>
        /// Returns the index of a given SingleKeyFrame in the collection. 
        /// </summary>
        int IList.IndexOf(object keyFrame)
        {
            return IndexOf((SingleKeyFrame)keyFrame);
        }
 
        /// <summary>
        /// Returns the index of a given SingleKeyFrame in the collection. 
        /// </summary>
        public int IndexOf(SingleKeyFrame keyFrame)
        {
            ReadPreamble();
 
            return _keyFrames.IndexOf(keyFrame);
        }
 
        /// <summary>
        /// Inserts a SingleKeyFrame into a specific location in the collection. 
        /// </summary>
        void IList.Insert(int index, object keyFrame)
        {
            Insert(index, (SingleKeyFrame)keyFrame);
        }
 
        /// <summary>
        /// Inserts a SingleKeyFrame into a specific location in the collection. 
        /// </summary>
        public void Insert(int index, SingleKeyFrame keyFrame)
        {
            ArgumentNullException.ThrowIfNull(keyFrame);
 
            WritePreamble();
 
            OnFreezablePropertyChanged(null, keyFrame);
            _keyFrames.Insert(index, keyFrame);
 
            WritePostscript();
        }
 
        /// <summary>
        /// Returns true if the collection is frozen.
        /// </summary>
        public bool IsFixedSize
        {
            get
            {
                ReadPreamble();
 
                return IsFrozen;
            }
        }
 
        /// <summary>
        /// Returns true if the collection is frozen.
        /// </summary>
        public bool IsReadOnly
        {
            get
            {
                ReadPreamble();
 
                return IsFrozen;
            }
        }
 
        /// <summary>
        /// Removes a SingleKeyFrame from the collection.
        /// </summary>
        void IList.Remove(object keyFrame)
        {
            Remove((SingleKeyFrame)keyFrame);
        }
 
        /// <summary>
        /// Removes a SingleKeyFrame from the collection.
        /// </summary>
        public void Remove(SingleKeyFrame keyFrame)
        {
            WritePreamble();
 
            if (_keyFrames.Contains(keyFrame))
            {
                OnFreezablePropertyChanged(keyFrame, null);
                _keyFrames.Remove(keyFrame);
 
                WritePostscript();
            }
        }
 
        /// <summary>
        /// Removes the SingleKeyFrame at the specified index from the collection.
        /// </summary>
        public void RemoveAt(int index)
        {
            WritePreamble();
 
            OnFreezablePropertyChanged(_keyFrames[index], null);
            _keyFrames.RemoveAt(index);
 
            WritePostscript();
        }
 
        /// <summary>
        /// Gets or sets the SingleKeyFrame at a given index.
        /// </summary>
        object IList.this[int index]
        {
            get
            {
                return this[index];
            }
            set
            {
                this[index] = (SingleKeyFrame)value;
            }
        }
 
        /// <summary>
        /// Gets or sets the SingleKeyFrame at a given index.
        /// </summary>
        public SingleKeyFrame this[int index]
        {
            get
            {
                ReadPreamble();
 
                return _keyFrames[index];
            }
            set
            {
                if (value == null)
                {
                    throw new ArgumentNullException(String.Format(CultureInfo.InvariantCulture, "SingleKeyFrameCollection[{0}]", index));
                }
 
                WritePreamble();
 
                if (value != _keyFrames[index])
                {
                    OnFreezablePropertyChanged(_keyFrames[index], value);
                    _keyFrames[index] = value;
 
                    Debug.Assert(_keyFrames[index] != null);
 
                    WritePostscript();
                }
            }
        }
 
        #endregion
    }
}