BlogEngine.net学习(一)——实体类

    在BlogEngine.net中处理的和业务相关的实体有Post(文章),Page(页面),Category(目录)。其中的类关系图如下
所有需要发布的实体都需要实现IPublishiable接口。其中业务实体都可对应多个目录,则在IPublishiable接口中有   StateList<Category> Categories { get;}字段。StateList可以检测是否已经修改过。
其中实现如下:
 1       ///   <summary>
 2       ///  A generic collection with the ability to 
 3       ///  check if it has been changed.
 4       ///   </summary>
 5      [System.Serializable]
 6       public   class  StateList < T >  : System.Collections.Generic.List < T >
 7      {
 8 
 9           #region  Base overrides
10           ///   <summary>
11           ///  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.
12           ///   </summary>
13           ///   <returns>
14           ///  A hash code for the current  <see cref="T:System.Object"></see> .
15           ///   </returns>
16           public   override   int  GetHashCode()
17          {
18               string  hash  =   string .Empty;
19               foreach  (T item  in   this )
20              {
21                  hash  +=  item.GetHashCode().ToString();
22              }
23 
24               return  hash.GetHashCode();
25          }
26 
27           ///   <summary>
28           ///  Determines whether the specified  <see cref="T:System.Object"></see>  is equal to the current  <see cref="T:System.Object"></see> .
29           ///   </summary>
30           ///   <param name="obj"> The  <see cref="T:System.Object"></see>  to compare with the current  <see cref="T:System.Object"></see> . </param>
31           ///   <returns>
32           ///  true if the specified  <see cref="T:System.Object"></see>  is equal to the current  <see cref="T:System.Object"></see> ; otherwise, false.
33           ///   </returns>
34           public   override   bool  Equals( object  obj)
35          {
36               if  (obj  ==   null )
37              {
38                   return   false ;
39              }
40 
41               if  (obj.GetType()  ==   this .GetType())
42              {
43                   return  obj.GetHashCode()  ==   this .GetHashCode();
44              }
45 
46               return   false ;
47          }
48 
49           #endregion
50 
51           private   int  _HasCode  =   0 ;
52 
53           ///   <summary>
54           ///  Gets if this object's data has been changed.
55           ///   </summary>
56           ///   <returns> A value indicating if this object's data has been changed. </returns>
57           public   virtual   bool  IsChanged
58          {
59               get
60              {
61                   return   this .GetHashCode()  !=  _HasCode;
62              }
63          }
64 
65           ///   <summary>
66           ///  Marks the object as being clean, 
67           ///  which means not changed.
68           ///   </summary>
69           public   virtual   void  MarkOld()
70          {
71              _HasCode  =   this .GetHashCode();
72               base .TrimExcess();
73          }
74      }
75 

转载于:https://www.cnblogs.com/believe3301/archive/2008/06/13/1219480.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值