Visual Studio 2008+NClay小试牛刀

http://tech.ddvip.com   2008年01月22日    社区交流

内容摘要:本文给出用VS 2008结合NClay进行SmallBlog程序的编写步骤和具体的源代码,供大家参考!

  NClay的原则是所有逻辑处理必须以接口的方式体现,所以在设计阶段必须构造业务输出和输入的逻辑接口。

public interface ICategoryDelete
{
 string CategoryID
 {
get;
set;
 }
}
public void Delete(ICategoryDelete logic)
{
 if (!NClay.Common.IsEmpty(logic.CategoryID))
 {
if ((DB.Post.CategoryID == logic.CategoryID).CountOf<Entities.Post>() > 0)
{
 throw new LogicException("有文章在此类别中不能删除!");
}
(DB.Category.CategoryID == logic.CategoryID).Delete<Entities.Category>();
 }
}

  VS 2008对代码的感知支持有所提高,编辑器能直接感知到表达式所返回的类型:

Visual Studio 2008+NClay小试牛刀

  图3

  视图

  由于VS 2008对默认属性的支持,这样大大减少了NClay下的视图代码;在VS 2005里,不得不对编辑器生成的接口代码进行调整。而VS 2008下直接编辑生成接口代码就可以,省了不少修改的工作。

[NClay.MVC.Action(ActionType = NClay.MVC.ActionType.All,
Tag = "~/Default.aspx", Services = new Type[] {
typeof(Logic.Post.IPostView) })]
public class Default :BaseView ,Logic.Post.IPostView
{
 #region IPostView 成员
public string CategoryID
 { get; set; }
public System.Collections.Generic.IList<SmallBlog.Entities.PostView> Posts
 { get; set; }
#endregion
 #region IDataPageProperty 成员
 [NClay.MVC.Bind(typeof(NClay.DataPage))]
 public NClay.IDataPage DataPage
 { get; set; }
 #endregion
}

  AOP扩展

来源:天极    作者:拌瓜    责编:豆豆技术应用

正在加载评论...