TemplateParameterCollection.cs :  » Bloggers » SubText » Subtext » Scripting » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Bloggers » SubText 
SubText » Subtext » Scripting » TemplateParameterCollection.cs
#region Disclaimer/Info

///////////////////////////////////////////////////////////////////////////////////////////////////
// Subtext WebLog
// 
// Subtext is an open source weblog system that is a fork of the .TEXT
// weblog system.
//
// For updated news and information please visit http://subtextproject.com/
// Subtext is hosted at Google Code at http://code.google.com/p/subtext/
// The development mailing list is at subtext@googlegroups.com 
//
// This project is licensed under the BSD license.  See the License.txt file for more information.
///////////////////////////////////////////////////////////////////////////////////////////////////

#endregion

using System;
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;

namespace Subtext.Scripting{
    /// <summary>
    /// A collection of <see cref="TemplateParameter"/> instances.
    /// </summary>
    public class TemplateParameterCollection : ICollection<TemplateParameter>
    {
        readonly List<TemplateParameter> _list = new List<TemplateParameter>();

        /// <summary>
        /// Gets the <see cref="TemplateParameter"/> at the specified index.
        /// </summary>
        /// <value></value>
        public TemplateParameter this[int index]
        {
            get { return _list[index]; }
        }

        /// <summary>
        /// Gets the <see cref="TemplateParameter"/> with the specified name.
        /// </summary>
        /// <value></value>
        public TemplateParameter this[string name]
        {
            get
            {
                foreach(TemplateParameter parameter in _list)
                {
                    if(String.Equals(parameter.Name, name, StringComparison.OrdinalIgnoreCase))
                    {
                        return parameter;
                    }
                }
                return null;
            }
        }

        #region ICollection<TemplateParameter> Members

        void ICollection<TemplateParameter>.Add(TemplateParameter item)
        {
            Add(item);
        }

        public void Clear()
        {
            _list.Clear();
        }

        /// <summary>
        /// Gets a value indicating whether the collection contains the specified 
        /// <see cref="TemplateParameter">Script</see>.
        /// </summary>
        public bool Contains(TemplateParameter item)
        {
            if(item == null)
            {
                throw new ArgumentNullException("item");
            }

            return Contains(item.Name);
        }

        public void CopyTo(TemplateParameter[] array, int arrayIndex)
        {
            _list.CopyTo(array, arrayIndex);
        }

        public int Count
        {
            get { return _list.Count; }
        }

        public bool IsReadOnly
        {
            get { return false; }
        }

        /// <summary>
        /// Removes the specified value.
        /// </summary>
        public bool Remove(TemplateParameter item)
        {
            return _list.Remove(item);
        }

        #endregion

        #region IEnumerable<TemplateParameter> Members

        IEnumerator<TemplateParameter> IEnumerable<TemplateParameter>.GetEnumerator()
        {
            return _list.GetEnumerator();
        }

        public IEnumerator GetEnumerator()
        {
            return _list.GetEnumerator();
        }

        #endregion

        /// <summary>
        /// Determines whether [contains] [the specified name].
        /// </summary>
        /// <param name="name">The name.</param>
        /// <returns>
        ///   <c>true</c> if [contains] [the specified name]; otherwise, <c>false</c>.
        /// </returns>
        public bool Contains(string name)
        {
            return this[name] != null;
        }

        /// <summary>
        /// Creates a template parameter from a match.
        /// </summary>
        /// <param name="match">The match.</param>
        /// <returns></returns>
        public TemplateParameter Add(Match match)
        {
            if(match == null)
            {
                throw new ArgumentNullException("match");
            }

            if(this[match.Groups["name"].Value] != null)
            {
                return this[match.Groups["name"].Value];
            }

            var parameter = new TemplateParameter(match.Groups["name"].Value, match.Groups["type"].Value,
                                                  match.Groups["default"].Value);
            Add(parameter);
            return parameter;
        }

        /// <summary>
        /// Adds the specified value. If it already exists, returns 
        /// the existing one, otherwise just returns the one you added.
        /// </summary>
        /// <param name="value">Value.</param>
        /// <returns></returns>
        public TemplateParameter Add(TemplateParameter value)
        {
            if(value == null)
            {
                throw new ArgumentNullException("value");
            }

            if(Contains(value))
            {
                return this[value.Name];
            }
            _list.Add(value);
            value.ValueChanged += OnValueChanged;
            return value;
        }

        /// <summary>
        /// Adds the contents of another <see cref="ScriptCollection">ScriptCollection</see> 
        /// to the end of the collection.
        /// </summary>
        /// <param name="value">A <see cref="ScriptCollection">ScriptCollection</see> containing the <see cref="TemplateParameter"/>s to add to the collection. </param>
        public void AddRange(IEnumerable<TemplateParameter> value)
        {
            foreach(TemplateParameter parameter in value)
            {
                Add(parameter);
            }
        }

        /// <summary>
        /// Gets the index in the collection of the specified 
        /// <see cref="TemplateParameter">Script</see>, if it exists in the collection.
        /// </summary>
        /// <param name="value">The <see cref="TemplateParameter">Script</see> 
        /// to locate in the collection.</param>
        /// <returns>The index in the collection of the specified object, if found; otherwise, -1.</returns>
        public int IndexOf(TemplateParameter value)
        {
            return _list.IndexOf(value);
        }

        /// <summary>
        /// Provides a shortcut to set a value.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="value">The value.</param>
        public void SetValue(string name, string value)
        {
            if(this[name] != null)
            {
                this[name].Value = value;
            }
        }

        private void OnValueChanged(object sender, ParameterValueChangedEventArgs args)
        {
            OnValueChanged(args);
        }

        protected void OnValueChanged(ParameterValueChangedEventArgs args)
        {
            EventHandler<ParameterValueChangedEventArgs> changeEvent = ValueChanged;
            if(changeEvent != null)
            {
                changeEvent(this, args);
            }
        }

        /// <summary>
        /// Event raised when any parameter within this collection changes 
        /// its values.
        /// </summary>
        public event EventHandler<ParameterValueChangedEventArgs> ValueChanged;
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.