HashTool.cs
上传用户:husern
上传日期:2022-03-24
资源大小:534k
文件大小:2k
- // -- FILE ------------------------------------------------------------------
- // name : HashTool.cs
- // project : Itenso Web User Forms
- // created : Jani Giannoudis - 2008.10.30
- // language : c#
- // environment: .NET 2.0
- // copyright : (c) 2008 by Itenso GmbH, Switzerland
- // --------------------------------------------------------------------------
- using System;
- using System.Collections;
- using System.Reflection;
- using System.Text;
- namespace Itenso.WebUserForms.Data
- {
- // ------------------------------------------------------------------------
- /// <summary>
- /// Some hash utility methods for collections.
- /// </summary>
- internal sealed class HashTool
- {
- // ----------------------------------------------------------------------
- public static int AddHashCode( int hash, object obj )
- {
- int combinedHash = obj != null ? obj.GetHashCode() : 0;
- if ( hash != 0 ) // perform this check to prevent FxCop warning 'op could overflow'
- {
- combinedHash += hash * 31;
- }
- return combinedHash;
- } // AddHashCode
- // ----------------------------------------------------------------------
- public static int AddHashCode( int hash, int objHash )
- {
- int combinedHash = objHash;
- if ( hash != 0 ) // perform this check to prevent FxCop warning 'op could overflow'
- {
- combinedHash += hash * 31;
- }
- return combinedHash;
- } // AddHashCode
- // ----------------------------------------------------------------------
- public static int ComputeHashCode( IEnumerable enumerable )
- {
- int hash = 1;
- if ( enumerable == null )
- {
- throw new ArgumentNullException( "enumerable" );
- }
- foreach ( object item in enumerable )
- {
- hash = hash * 31 + ( item != null ? item.GetHashCode() : 0 );
- }
- return hash;
- } // ComputeHashCode
- // ----------------------------------------------------------------------
- /// <summary>
- /// prevent instantiation of class utility.
- /// </summary>
- private HashTool()
- {
- } // HashTool
- } // class HashTool
- } // namespace Itenso.WebUserForms.Data
- // -- EOF -------------------------------------------------------------------