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

namespace ThoughtWorks.CruiseControl.Remote.Parameters{
    /// <summary>
    /// Abstract base class for parameters.
    /// </summary>
    /// <title>Parameters</title>
    [Serializable]
    [XmlInclude(typeof(TextParameter))]
    [XmlInclude(typeof(SelectParameter))]
    [XmlInclude(typeof(NumericParameter))]
    [XmlInclude(typeof(DateParameter))]
    [XmlInclude(typeof(BooleanParameter))]
    public abstract class ParameterBase
    {
        #region Private fields
        private string myName;
        private string myDisplayName = null;
        private string myDescription = null;
        private string myDefault = null;
        #endregion

        #region Constructors
        /// <summary>
        /// Initialise a new instance of a <see cref="ParameterBase"/>.
        /// </summary>
        public ParameterBase()
        {
        }

        /// <summary>
        /// Initialise an instance of a <see cref="ParameterBase"/> with a name.
        /// </summary>
        public ParameterBase(string name)
        {
            myName = name;
        }
        #endregion

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

        #region DisplayName
        /// <summary>
        /// The display name of the parameter.
        /// </summary>
        /// <version>1.5</version>
        /// <default>None</default>
#if !NoReflector
        [ReflectorProperty("display", Required = false)]
#endif
        [XmlAttribute("display")]
        public virtual string DisplayName
        {
            get { return myDisplayName ?? myName; }
            set { myDisplayName = value; }
        }
        #endregion

        #region Description
        /// <summary>
        /// The description of the parameter.
        /// </summary>
        /// <version>1.5</version>
        /// <default>None</default>
#if !NoReflector
        [ReflectorProperty("description", Required = false)]
#endif
        [XmlElement("description")]
        public virtual string Description
        {
            get { return myDescription; }
            set { myDescription = value; }
        }
        #endregion

        #region DefaultValue
        /// <summary>
        /// The default value to use.
        /// </summary>
        /// <version>1.5</version>
        /// <default>None</default>
#if !NoReflector
        [ReflectorProperty("default", Required = false)]
#endif
        [XmlIgnore]
        public virtual string DefaultValue
        {
            get { return myDefault; }
            set { myDefault = value; }
        }
        #endregion

        #region ClientDefaultValue
        /// <summary>
        /// The default value for the clients to use.
        /// </summary>
        [XmlElement("default")]
        public virtual string ClientDefaultValue
        {
            get { return myDefault; }
            set { myDefault = value; }
        }
        #endregion

        #region DataType
        /// <summary>
        /// The type of the parameter.
        /// </summary>
        public abstract Type DataType { get; }
        #endregion

        #region AllowedValues
        /// <summary>
        /// An array of allowed values.
        /// </summary>
        [XmlElement("allowedValue")]
        public abstract string[] AllowedValues { get; }
        #endregion
        #endregion

        #region Public methods
        #region Validate()
        /// <summary>
        /// Validates the parameter.
        /// </summary>
        /// <param name="value">The value to check.</param>
        /// <returns>Any validation exceptions.</returns>
        public abstract Exception[] Validate(string value);
        #endregion

        #region Convert()
        /// <summary>
        /// Converts the parameter into the value to use.
        /// </summary>
        /// <param name="value">The value to convert.</param>
        /// <returns>The value to use.</returns>
        public virtual object Convert(string value)
        {
            object actualValue = value;
            if (DataType != typeof(string))
            {
                actualValue = System.Convert.ChangeType(value, DataType);
            }
            return actualValue;
        }
        #endregion

        #region GenerateClientDefault()
        /// <summary>
        /// Updates the client default value.
        /// </summary>
        public virtual void GenerateClientDefault()
        {
        }
        #endregion
        #endregion

        #region Protected methods
        #region GenerateException()
        /// <summary>
        /// Generates a validation exception.
        /// </summary>
        /// <param name="message"></param>
        /// <param name="values"></param>
        /// <returns></returns>
        protected virtual Exception GenerateException(string message, params object[] values)
        {
            string actualMessage = message.Replace("{name}", DisplayName);
            Exception exception = new Exception(
                string.Format(actualMessage,
                values));
            return exception;
        }
        #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.