//===============================================================================
// 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/>
    public class ResultVariableDeclaration
    {
        Type resultType;
        string resultName;

        /// <summary>
        /// Initializes a new instance of the <see cref="T:ResultVariableDeclaration"/> class.
        /// </summary>
        /// <param name="resultType">Type of the result.</param>
        /// <param name="resultName">Name of the result.</param>
        public ResultVariableDeclaration(Type resultType, string resultName)
        {
            this.resultType = resultType;
            this.resultName = resultName;
        }

        /// <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)
        {
            ResultVariableDeclaration other = obj as ResultVariableDeclaration;
            if (other == null) return false;

            return resultType.Equals(other.resultType) && resultName.Equals(other.resultName);
        }

        /// <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 CodeVariableDeclarationStatement ToCodeDom()
        {
            CodeVariableDeclarationStatement declaration = new CodeVariableDeclarationStatement(resultType, resultName, new CodeObjectCreateExpression(resultType, new CodeExpression[0]));
            return declaration;
        }
    }
}
