//===============================================================================
// Microsoft patterns & practices
// Web Service Software Factory
//===============================================================================
// Copyright  Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===============================================================================

using System;
using System.Collections.Generic;
using System.Text;
using System.CodeDom;

namespace Microsoft.Practices.SoftwareFactories.ServiceFactory.Actions.CodeDom.Helpers
{
    /// <summary>
    /// Helper class for accessing the method parameters.
    /// </summary>
    public class MethodParameter
    {
        Type type;
        string name;

        /// <summary>
        /// Initializes a new instance of the <see cref="T:MethodParameter"/> class.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="name">The name.</param>
        public MethodParameter(Type type, string name)
        {
            this.type = type;
            this.name = name;
        }

        /// <summary>
        /// Determines whether the specified <see cref="T:System.Object"></see> is equal to the current <see cref="T:System.Object"></see>.
        /// </summary>
        /// <param name="obj">The <see cref="T:System.Object"></see> to compare with the current <see cref="T:System.Object"></see>.</param>
        /// <returns>
        /// true if the specified <see cref="T:System.Object"></see> is equal to the current <see cref="T:System.Object"></see>; otherwise, false.
        /// </returns>
        public override bool Equals(object obj)
        {
            MethodParameter other = obj as MethodParameter;
            if (other == null) return false;

            return type.Equals(other.type) && name.Equals(other.name);
        }

        /// <summary>
        /// Serves as a hash function for a particular type. <see cref="M:System.Object.GetHashCode"></see> is suitable for use in hashing algorithms and data structures like a hash table.
        /// </summary>
        /// <returns>
        /// A hash code for the current <see cref="T:System.Object"></see>.
        /// </returns>
        public override int GetHashCode()
        {
            return base.GetHashCode();
        }

        /// <summary>
        /// Toes the code DOM.
        /// </summary>
        /// <returns></returns>
        public CodeParameterDeclarationExpression ToCodeDom()
        {
            CodeParameterDeclarationExpression paramExpression = new CodeParameterDeclarationExpression(type, name);

            return paramExpression;
        }
    }
}
