NameValuePair.cs :  » Build-Systems » CruiseControl.NET » ThoughtWorks » CruiseControl » Remote » 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 » Build Systems » CruiseControl.NET 
CruiseControl.NET » ThoughtWorks » CruiseControl » Remote » NameValuePair.cs
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
#if !NoReflector
using Exortech.NetReflector;
#endif

namespace ThoughtWorks.CruiseControl.Remote{
    /// <title>Named Value</title>
    /// <version>1.4.4</version>
    /// <summary>
    /// <para>
    /// A value with an associated name. This is a generic configuration item that is used in other configuration
    /// elements.
    /// </para>
    /// </summary>
    /// <example>
    /// <code >
    /// &lt;namedValue name="The Name" value="something" /&gt;
    /// </code>
    /// </example>
    [Serializable]
#if !NoReflector
    [ReflectorType("namedValue")]
#endif
    public class NameValuePair
        : IEquatable<NameValuePair>
    {
        #region Private fields
        private string name;
        private string namedValue;
        #endregion

        #region Constructors
        /// <summary>
        /// Starts a new blank <see cref="NameValuePair"/>.
        /// </summary>
        public NameValuePair() { }

        /// <summary>
        /// Starts a new <see cref="NameValuePair"/> with a name and value.
        /// </summary>
        public NameValuePair(string name, string value)
        {
            this.name = name;
            this.namedValue = value;
        }
        #endregion

        #region Public properties
        #region Name
        /// <summary>
        /// The name of the value.
        /// </summary>
        /// <version>1.4.4</version>
        /// <default>n/a</default>
        [XmlAttribute("name")]
#if !NoReflector
        [ReflectorProperty("name")]
#endif
        public string Name
        {
            get { return name; }
            set { name = value; }
        }
        #endregion

        #region Value
        /// <summary>
        /// The actual value.
        /// </summary>
        /// <version>1.4.4</version>
        /// <default>n/a</default>
        [XmlAttribute("value")]
#if !NoReflector
        [ReflectorProperty("value", Required = false)]
#endif
        public string Value
        {
            get { return namedValue; }
            set { namedValue = value; }
        }
        #endregion
        #endregion

        #region Public methods
        #region ToDictionary()
        /// <summary>
        /// Converts a list of <see cref="NameValuePair"/> to a dictionary of strings.
        /// </summary>
        /// <param name="values"></param>
        /// <returns></returns>
        public static Dictionary<string, string> ToDictionary(List<NameValuePair> values)
        {
            Dictionary<string, string> dictionary = new Dictionary<string, string>();
            if (values != null)
            {
                foreach (NameValuePair value in values)
                {
                    dictionary.Add(value.name, value.Value);
                }
            }
            return dictionary;
        }
        #endregion

        #region FromDictionary()
        /// <summary>
        /// Converts a list of <see cref="NameValuePair"/> from a dictionary of strings.
        /// </summary>
        /// <param name="values"></param>
        /// <returns></returns>
        public static List<NameValuePair> FromDictionary(Dictionary<string, string> values)
        {
            List<NameValuePair> pairs = new List<NameValuePair>();
            if (values != null)
            {
                foreach (string key in values.Keys)
                {
                    pairs.Add(new NameValuePair(key, values[key]));
                }
            }
            return pairs;
        }
        #endregion

        #region FindNamedValue()
        /// <summary>
        /// Attempts to find a named value.
        /// </summary>
        /// <param name="values"></param>
        /// <param name="name">The name of the value to find.</param>
        /// <returns></returns>
        public static string FindNamedValue(List<NameValuePair> values, string name)
        {
            string actualValue = null;
            if (values != null)
            {
                foreach (NameValuePair value in values)
                {
                    if (string.Equals(value.name, name, StringComparison.InvariantCultureIgnoreCase))
                    {
                        actualValue = value.Value;
                        break;
                    }
                }
            }
            return actualValue;
        }
        #endregion

        #region Copy()
        /// <summary>
        /// Copies all the values from a dictionary into a list.
        /// </summary>
        /// <param name="dictionary"></param>
        /// <param name="list"></param>
        public static void Copy(Dictionary<string, string> dictionary, List<NameValuePair> list)
        {
            if (dictionary != null)
            {
                foreach (var pair in dictionary)
                {
                    list.Add(new NameValuePair(pair.Key, pair.Value));
                }
            }
        }

        /// <summary>
        /// Copies all the values from one list to another.
        /// </summary>
        /// <param name="destination"></param>
        /// <param name="source"></param>
        public static void Copy(List<NameValuePair> source, List<NameValuePair> destination)
        {
            if (source != null)
            {
                foreach (var pair in source)
                {
                    destination.Add(new NameValuePair(pair.Name, pair.Value));
                }
            }
        }
        #endregion

        #region GetHashCode()
        /// <summary>
        /// Returns a hash code for this instance.
        /// </summary>
        /// <returns>
        /// A hash code for this instance, suitable for use in hashing algorithms and data structures like
        /// a hash table. 
        /// </returns>
        public override int GetHashCode()
        {
            return this.name == null ? 0 : this.name.GetHashCode();
        }
        #endregion

        #region Equals()
        /// <summary>
        /// Determines whether the specified <see cref="Object"/> is equal to this instance.
        /// </summary>
        /// <param name="obj">The <see cref="Object"/> to compare with this instance.</param>
        /// <returns>
        /// <c>true</c> if the specified <see cref="Object"/> is equal to this instance; otherwise, <c>false</c>.
        /// </returns>
        public override bool Equals(object obj)
        {
            return this.Equals(obj as NameValuePair);
        }

        /// <summary>
        /// Indicates whether the current object is equal to another object of the same type.
        /// </summary>
        /// <param name="other">An object to compare with this object.</param>
        /// <returns>
        /// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false.
        /// </returns>
        public bool Equals(NameValuePair other)
        {
            if (other == null)
            {
                return false;
            }

            return other.name == this.name;
        }
        #endregion
        #endregion
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.