/*
 * TypeList.cs --
 *
 * Copyright (c) 2007-2012 by Joe Mistachkin.  All rights reserved.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * RCS: @(#) $Id: $
 */

using System;
using System.Collections.Generic;
using Eagle._Attributes;
using Eagle._Components.Private;
using Eagle._Components.Public;
using Eagle._Constants;

namespace Eagle._Containers.Public
{
#if SERIALIZATION
    [Serializable()]
#endif
    [ObjectId("6002e634-1f30-4e30-b147-6aab6fab3c6a")]
    public sealed class TypeList : List<Type>
    {
        public TypeList()
            : base()
        {
            // do nothing.
        }

        ///////////////////////////////////////////////////////////////////////

        public TypeList(
            IEnumerable<Type> collection
            )
            : base(collection)
        {
            // do nothing.
        }

        ///////////////////////////////////////////////////////////////////////

        public ReturnCode ToList(
            string pattern,
            bool noCase,
            bool fullName,
            bool qualified,
            ref StringList list,
            ref Result error
            )
        {
            StringList inputList = new StringList();

            foreach (Type type in this)
                if (type != null)
                    inputList.Add(FormatOps.QualifiedAndOrFullName(
                        type, fullName, qualified, false));

            if (list == null)
                list = new StringList();

            return GenericOps<string>.FilterList(
                inputList, list, Index.Invalid, Index.Invalid,
                ToStringFlags.None, pattern, noCase, ref error);
        }

        ///////////////////////////////////////////////////////////////////////

        public string ToString(
            string pattern,
            bool noCase,
            bool qualified
            )
        {
            if (qualified)
            {
                StringList list = new StringList();

                foreach (Type type in this)
                    if (type != null)
                        list.Add(FormatOps.QualifiedName(type));

                return GenericOps<string>.ListToString(
                    list, Index.Invalid, Index.Invalid, ToStringFlags.None,
                    Characters.Space.ToString(), pattern, noCase);
            }
            else
            {
                return GenericOps<Type>.ListToString(
                    this, Index.Invalid, Index.Invalid, ToStringFlags.None,
                    Characters.Space.ToString(), pattern, noCase);
            }
        }

        ///////////////////////////////////////////////////////////////////////

        public string ToString(
            string pattern,
            bool noCase
            )
        {
            return ToString(pattern, noCase, false);
        }

        ///////////////////////////////////////////////////////////////////////

        #region System.Object Overrides
        public override string ToString()
        {
            return ToString(null, false);
        }
        #endregion
    }
}
