#region Apache License // // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. // The ASF licenses this file to you under the Apache License, Version 2.0 // (the "License"); you may not use this file except in compliance with // the License. You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #endregion using System; using System.Collections; namespace log4net.Util { /// /// An always empty . /// /// /// /// A singleton implementation of the /// interface that always represents an empty collection. /// /// /// Nicko Cadell /// Gert Driesen #if !NETCF [Serializable] #endif public sealed class EmptyCollection : ICollection { #region Private Instance Constructors /// /// Initializes a new instance of the class. /// /// /// /// Uses a private access modifier to enforce the singleton pattern. /// /// private EmptyCollection() { } #endregion Private Instance Constructors #region Public Static Properties /// /// Gets the singleton instance of the empty collection. /// /// The singleton instance of the empty collection. /// /// /// Gets the singleton instance of the empty collection. /// /// public static EmptyCollection Instance { get { return s_instance; } } #endregion Public Static Properties #region Implementation of ICollection /// /// Copies the elements of the to an /// , starting at a particular Array index. /// /// The one-dimensional /// that is the destination of the elements copied from /// . The Array must have zero-based /// indexing. /// The zero-based index in array at which /// copying begins. /// /// /// As the collection is empty no values are copied into the array. /// /// public void CopyTo(System.Array array, int index) { // copy nothing } /// /// Gets a value indicating if access to the is synchronized (thread-safe). /// /// /// true if access to the is synchronized (thread-safe); otherwise, false. /// /// /// /// For the this property is always true. /// /// public bool IsSynchronized { get { return true; } } /// /// Gets the number of elements contained in the . /// /// /// The number of elements contained in the . /// /// /// /// As the collection is empty the is always 0. /// /// public int Count { get { return 0; } } /// /// Gets an object that can be used to synchronize access to the . /// /// /// An object that can be used to synchronize access to the . /// /// /// /// As the collection is empty and thread safe and synchronized this instance is also /// the object. /// /// public object SyncRoot { get { return this; } } #endregion Implementation of ICollection #region Implementation of IEnumerable /// /// Returns an enumerator that can iterate through a collection. /// /// /// An that can be used to /// iterate through the collection. /// /// /// /// As the collection is empty a is returned. /// /// public IEnumerator GetEnumerator() { return NullEnumerator.Instance; } #endregion Implementation of IEnumerable #region Private Static Fields /// /// The singleton instance of the empty collection. /// private readonly static EmptyCollection s_instance = new EmptyCollection(); #endregion Private Static Fields } }