Exemplo n.º 1
0
        /// <summary>
        /// Returns all the items in the collection which match the flag specified.
        /// </summary>
        /// <param name="include">boolean to indicate if names are to be ignored or not, false for ignore.</param>
        /// <param name="flag">Flag that is present on the item such as disabled, tracked, throws, etc.</param>
        /// <returns>Returns a ModelItems collection</returns>
        /// <returns></returns>
        public virtual ModelItems <T> FindFlag(int flag, bool include)
        {
            //Construct the typed collection (ie: (Models)Find).
            //The simplest, without dealing with constructors, is to clone and clear
            ModelItems <T> items = (ModelItems <T>) this.Clone();

            items.Clear();

            //Note: there could be more than one (even by the same name)
            /// Implementation Note: All internal enumeration should be performed on this instead of _list
            /// to ensure that any overriden GetEnumerator() can dictate how enumeration is performed
            /// over the list items.
            foreach (T item in this)
            {
                if (include)
                {
                    if (item.IsFlag(flag))
                    {
                        items.Add(item);
                    }
                }
                else
                {
                    if (item.IsFlagExcept(flag))
                    {
                        items.Add(item);
                    }
                }
            }
            return(items);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns a collection of items found except those specified.
        /// </summary>
        /// <param name="names">Names to ignore while returning.</param>
        /// <returns>ModelItems collection</returns>
        public virtual ModelItems <T> FindExcept(params string[] names)
        {
            //Construct the typed collection (ie: (Models)Find).
            //The simplest, without dealing with constructors, is to clone and clear
            ModelItems <T> items = (ModelItems <T>) this.Clone();

            items.Clear();

            //Find all items that don't match ANY of the names
            //Note: This doesn't need to perserve the order, so matching this a seperate function (simplier)
            /// Implementation Note: All internal enumeration should be performed on this instead of _list
            /// to ensure that any overriden GetEnumerator() can dictate how enumeration is performed
            /// over the list items.
            foreach (T item in this)
            {
                bool matched = false;
                foreach (string name in names)
                {
                    //Delegate
                    if (String.Compare(item.Name, name, true /*ignore case*/) == 0)
                    {
                        matched = true;
                        break;
                    }
                }

                if (!matched)
                {
                    items.Add(item);
                }
            }
            return(items);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Returns a collection of items found for the given names.
        /// </summary>
        /// <param name="names">Names of items. (usually type.ToString)</param>
        /// <returns>ModelItems collection</returns>
        public virtual ModelItems <T> Find(params string[] names)
        {
            //Construct the typed collection (ie: (Models)Find).
            //The simplest, without dealing with constructors, is to clone and clear
            ModelItems <T> items = (ModelItems <T>) this.Clone();

            items.Clear();

            //Note: To perserve the order, we need to loop over the names in the outer loop
            //instead of the inner, which makes the exclusion (ie: include=false) more difficult
            foreach (string name in names)
            {
                /// Implementation Note: All internal enumeration should be performed on this instead of _list
                /// to ensure that any overriden GetEnumerator() can dictate how enumeration is performed
                /// over the list items.
                foreach (T item in this)
                {
                    //Compare
                    bool matched = String.Compare(item.Name, name, true /*ignore case*/) == 0;
                    if (matched)
                    {
                        items.Add(item);
                    }
                }
            }
            return(items);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Overridden Clone method to copy this item.
        /// </summary>
        /// <returns></returns>
        public virtual object                       Clone()
        {
            ModelItems <T> clone = (ModelItems <T>) this.MemberwiseClone();

            clone._list = new List <T>();
            clone.Add(this);
            return(clone);
        }
Exemplo n.º 5
0
 /// <summary>
 /// Removes a collection of model items from this collection.
 /// </summary>
 /// <param name="items"></param>
 /// <returns></returns>
 public virtual ModelItems <T> Remove(ModelItems <T> items)
 {
     foreach (T item in items)
     {
         this.Remove(item);
     }
     return(items);
 }
Exemplo n.º 6
0
 /// <summary>
 /// Adds another ModelItems collection to this collection.
 /// </summary>
 /// <param name="items"></param>
 /// <returns></returns>
 public virtual ModelItems <T> Add(ModelItems <T> items)
 {
     foreach (T item in items)
     {
         this.Add(item);
     }
     return(items);
 }
Exemplo n.º 7
0
 /// <summary>
 /// Named indexer.
 /// </summary>
 public virtual T this[string name]
 {
     //Find first, fail if not found, although make it easier to debug
     get
     {
         ModelItems <T> found = this.Find(name);
         if (found == null || found.Count <= 0)
         {
             throw new IndexOutOfRangeException(this.Name + "['" + name + "'] is not found");
         }
         return(found.First);
     }
 }
Exemplo n.º 8
0
        /// <summary>
        /// Returns a collection of ModelItems that do not define the given label
        /// </summary>
        /// <param name="label">Label to find by</param>
        /// <returns>Returns a ModelItem collection</returns>
        public virtual ModelItems <T> FindByNoLabel(object label)
        {
            //Construct itself without bothering about constructors.
            ModelItems <T> items = (ModelItems <T>) this.Clone();

            items.Clear();

            /// Implementation Note: All internal enumeration should be performed on this instead of _list
            /// to ensure that any overriden GetEnumerator() can dictate how enumeration is performed
            /// over the list items.
            foreach (T item in this)
            {
                if (item.CompareLabel(label) != 0)
                {
                    items.Add(item);
                }
            }

            return(items);
        }