StateCollection.cs :  » Bloggers » BlogEngine.NET » BlogEngine.Core » 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 » Bloggers » BlogEngine.NET 
BlogEngine.NET » BlogEngine.Core » StateCollection.cs
namespace BlogEngine.Core{
  /// <summary>
  /// A generic collection with the ability to 
  /// check if it has been changed.
  /// </summary>
  [System.Serializable]
  public class StateList<T> : System.Collections.Generic.List<T>
  {

    #region Base overrides

    ///// <summary>
    ///// Inserts an element into the collection at the specified index and marks it changed.
    ///// </summary>
    //protected override void InsertItem(int index, T item)
    //{
    //  base.InsertItem(index, item);
    //  _IsChanged = true;
    //}

    ///// <summary>
    ///// Removes all the items in the collection and marks it changed.
    ///// </summary>
    //protected override void ClearItems()
    //{
    //  base.ClearItems();
    //  _IsChanged = true;
    //}

    ///// <summary>
    ///// Removes the element at the specified index and marks the collection changed.
    ///// </summary>
    //protected override void RemoveItem(int index)
    //{
    //  base.RemoveItem(index);
    //  _IsChanged = true;
    //}

    ///// <summary>
    ///// Replaces the element at the specified index and marks the collection changed.
    ///// </summary>
    //protected override void SetItem(int index, T item)
    //{
    //  base.SetItem(index, item);
    //  _IsChanged = true;
    //}

    /// <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()
    {
      string hash = string.Empty;
      foreach (T item in this)
      {
        hash += item.GetHashCode().ToString();
      }

      return hash.GetHashCode();
    }

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

      if (obj.GetType() == this.GetType())
      {
        return obj.GetHashCode() == this.GetHashCode();
      }

      return false;
    }

    #endregion

    private int _HasCode = 0;

    /// <summary>
    /// Gets if this object's data has been changed.
    /// </summary>
    /// <returns>A value indicating if this object's data has been changed.</returns>
    public virtual bool IsChanged
    {
      get 
      {
        return this.GetHashCode() != _HasCode;
      }
    }

    /// <summary>
    /// Marks the object as being clean, 
    /// which means not changed.
    /// </summary>
    public virtual void MarkOld()
    {
      _HasCode = this.GetHashCode();
      base.TrimExcess();
    }

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