IIndexableContent接口如下:







这个接口定义了ContentChanged事件,本接口的作用定义了与索引有关的基础接口。
委托ContentChangedEventHandler如下:

类ContentChangedEventArgs如下:











关于EventArgs 类,在网上查了些资料,如下:
从代码你可以知道e是EventArgs类型的对象。那么你就该去看EventArgs类。
















-----------------------------------------------------------------------------------------------------------
下面看继承IIndexableContent接口的类
如:
Blog类,简要分析一下:
public class Blog : IIndexableContent
{
//继承了接口中事件的定义
public event ContentChangedEventHandler ContentChanged;
//触发事件方法的定义
protected void OnContentChanged(ContentChangedEventArgs e)
{
if (ContentChanged != null)
{
ContentChanged(this, e);
}
}
//调用OnContentChanged方法的函数
之一:
private bool Create()
{
int newID = 0;
blogGuid = Guid.NewGuid();
createdUtc = DateTime.UtcNow;
newID = DBBlog.AddBlog(
this.blogGuid,
this.moduleGuid,
this.moduleID,
this.userName,
this.title,
this.excerpt,
this.description,
this.startDate,
this.isInNewsletter,
this.includeInFeed,
this.allowCommentsForDays,
this.location,
this.userGuid,
this.createdUtc);
this.itemID = newID;
bool result = (newID > 0);
//IndexHelper.IndexItem(this);
if (result)
{
ContentChangedEventArgs e = new ContentChangedEventArgs();
OnContentChanged(e);
}
return result;
}
之二:
public bool Delete()
{
bool result = DBBlog.DeleteItemCategories(itemID);
DBBlog.DeleteAllCommentsForBlog(itemID);
DBBlog.UpdateCommentStats(this.moduleID);
if (result)
{
result = DBBlog.DeleteBlog(this.itemID);
DBBlog.UpdateEntryStats(this.moduleID);
ContentChangedEventArgs e = new ContentChangedEventArgs();
e.IsDeleted = true;
OnContentChanged(e);
}
return result;
}
即在Delete方法中,事件类型的IsDeleted属性为True
--------------------------------------------------------------------------------------------
在Blog类中,定义事件ContentChanged,这个事件是如何被调用的呢?
在BlogEdit.CS中
点击更新按钮时相关代码如下:






删除时代码如下:









我们可以看到,在上面的代码中定义了ContentChanged事件触发时调用的方法。
在blog.Delete()方法中会触发这个事件
---------------------------------------------------------------------------------------------------------