MethodSignature.cs :  » Testing » MockObjects » DotNetMock » Dynamic » 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 » Testing » MockObjects 
MockObjects » DotNetMock » Dynamic » MethodSignature.cs
using System;
using System.Reflection;
namespace DotNetMock.Dynamic{
  /// <summary>
  /// Class encapsulates a method signature of a single method.
  /// </summary>
  /// <author>Roman V. Gavrilov</author>
  /// <author>Griffin Caprio</author>
  public class MethodSignature
  {
    private Type[] _paramTypes;
    private string _methodName;
    private Type _returnType;

    #region Constructors
    /// <summary>
    /// Create new instance based on given information.
    /// </summary>
    /// <param name="methodName">Name of the method.</param>
    /// <param name="returnType">Method return type.</param>
    /// <param name="paramTypes">Parameter types.</param>
    public MethodSignature( string methodName, Type returnType, params Type[] paramTypes )
    {
      _methodName = methodName;
      _returnType = returnType;
      _paramTypes = ( Type[] )paramTypes.Clone( );
    }
    /// <summary>
    /// Create new instance of method signature from MethodInfo.
    /// </summary>
    /// <param name="methodInfo">MethodInfo to use for method signature instantiation.</param>
    public MethodSignature( MethodInfo methodInfo )
    {
      ParameterInfo[] paramInfos = methodInfo.GetParameters( );
      Type[] paramTypes = new Type[paramInfos.Length];
      foreach ( ParameterInfo paramInfo in paramInfos )
      {
        paramTypes[ paramInfo.Position ] = paramInfo.ParameterType;
      }
      _methodName = methodInfo.Name;
      _returnType = methodInfo.ReturnType;
      _paramTypes = paramTypes;
    }
    #endregion

    #region Public Properties
    /// <summary>
    /// Returns <see cref="DotNetMock.Dynamic.MethodSignature"/>s parameter types.
    /// </summary>
    public Type[] ParamTypes
    {
      get
      {
        return _paramTypes;
      }
    }
    /// <summary>
    /// Returns <see cref="DotNetMock.Dynamic.MethodSignature"/>s method name.
    /// </summary>
    public string MethodName
    {
      get
      {
        return _methodName;
      }
    }
    /// <summary>
    /// Returns <see cref="DotNetMock.Dynamic.MethodSignature"/>s return type.
    /// </summary>
    public Type ReturnType
    {
      get
      {
        return _returnType;
      }
    }
    #endregion

    /// <summary>
    /// Compare two signatures by content.
    /// </summary>
    public override bool Equals( object obj )
    {
      if ( obj == null )
      {
        return false;
      }
      if ( !( obj is MethodSignature ) )
      {
        return false;
      }
      MethodSignature that = ( MethodSignature )obj;
      if ( that.MethodName.CompareTo( this.MethodName ) != 0 )
      {
        return false;
      }
      if ( !that.ReturnType.Equals( this.ReturnType ) )
      {
        return false;
      }
      if ( that.ParamTypes.Length != this.ParamTypes.Length )
      {
        return false;
      }
      for ( int idx = 0; idx < that.ParamTypes.Length; ++idx )
      {
        if ( !that.ParamTypes[ idx ].Equals( this.ParamTypes[ idx ] ) )
        {
          return false;
        }
      }
      return true;
    }
    /// <summary>
    /// Returns string representation of the instance of <see cref="DotNetMock.Dynamic.MethodSignature"/>
    /// </summary>
    /// <returns>string representation of the instance of <see cref="DotNetMock.Dynamic.MethodSignature"/></returns>
    public override string ToString( )
    {
      string paramTypesString = null;
      foreach ( Type paramType in _paramTypes )
      {
        if ( paramTypesString != null )
        {
          paramTypesString += ", ";
        }
        paramTypesString += paramType.ToString( );
      }
      string str = string.Format( "{0} {1}({2})", _returnType.ToString( ), _methodName, paramTypesString );
      return str;
    }
    /// <summary>
    /// Returns hashcode of base class
    /// </summary>
    /// <returns></returns>
    public override int GetHashCode( )
    {
      return base.GetHashCode( );
    }

  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.