惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 叶小钗
D
Docker
Google DeepMind News
Google DeepMind News
Y
Y Combinator Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Blog — PlanetScale
Blog — PlanetScale
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
U
Unit 42
博客园 - 【当耐特】
N
Netflix TechBlog - Medium
V
Visual Studio Blog
Microsoft Azure Blog
Microsoft Azure Blog
博客园_首页
Recent Announcements
Recent Announcements
GbyAI
GbyAI
T
Tailwind CSS Blog
S
SegmentFault 最新的问题
WordPress大学
WordPress大学
T
The Blog of Author Tim Ferriss
Engineering at Meta
Engineering at Meta
L
LangChain Blog
A
About on SuperTechFans
M
MIT News - Artificial intelligence
B
Blog

博客园 - TG.Yang's IT Space

提高工作效率之数据库工具 Unity(3) Unity(2)生命周期 Unity(1)控制反转 (转)常用的js代码 转:Oracle数据导入导出imp/exp命令 AspNet2.0页面生命周期(转) offsetLeft,Left,clientLeft的区别 发邮件窗体【支持编辑邮件模板,使用wse多线程上传附件及发邮件(带附件)】以及在服务器端自动发邮件 (mark)Oracle Update Statements Oracle 8i and 9i分析函数(转) row_number()over函数的使用(转) Community Server 资源 13个在线web2.0风格生成器 jQuery1.2选择器(转) 键盘输入工作原理 ORACLE 中ROWNUM用法总结 SQLServer和Oracle的常用函数对比 如何在Oracle里实现自增
BlogEngine.net学习(一)——实体类
TG.Yang's IT Space · 2008-06-13 · via 博客园 - TG.Yang's IT Space

    在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