IIndexableContent接口-转
IIndexableContent接口如下:
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
这个接口定义了ContentChanged事件,本接口的作用定义了与索引有关的基础接口。
委托ContentChangedEventHandler如下:
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
类ContentChangedEventArgs如下:
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
关于EventArgs 类,在网上查了些资料,如下:
从代码你可以知道e是EventArgs类型的对象。那么你就该去看EventArgs类。
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
几乎什么也没做是吧?对,就是实例化了一个对象。不过我们可以继承这个基类,开发自己的MyEventArgs类,里面可以包含一些fields。主要用来触发事件的时候同时传递一些参数。当然你也可以不定义这么一个事件参数类,而是通过定一个包含长长的参数列表的委托来做,当然这样代码也就不美观了。
-----------------------------------------------------------------------------------------------------------
下面看继承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方法中,ContentChangedEventArgs类的IsDeleted属性被赋值。
即在Delete方法中,事件类型的IsDeleted属性为True
--------------------------------------------------------------------------------------------
在Blog类中,定义事件ContentChanged,这个事件是如何被调用的呢?
在BlogEdit.CS中
点击更新按钮时相关代码如下:
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
删除时代码如下:
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
我们可以看到,在上面的代码中定义了ContentChanged事件触发时调用的方法。
在blog.Delete()方法中会触发这个事件
posted on 2013-01-16 15:50 Chandler.C 阅读(159) 评论(0) 编辑 收藏 举报