首页 / 软件开发 / .NET编程技术 / .NET组件编程(4) 用户自定义Property Editor的调试
.NET组件编程(4) 用户自定义Property Editor的调试2011-09-26 博客园 mapserver园子里的高人太多了,第2章遗留下来的Property DefaultValueAttribute问题解决掉了,感谢Colin Han的帮助,我对DefaultValueAttribute的理解有点误解了,msdn中对DefaultValueAttribute的说明为 : “可视化设计器可以使用默认值重置成员的值。代码生成器也可使用默认值确定是否为成员生成代码 ”,我把其理解为了创建Component时,对标示有DefaultValueAttribute的Property产生默认值,Colin Han的解释为:“这个特性可以帮助IDE减少Code生成的工作,如果设计时某个标示有 DefaultValueAttribute的Property的值和DefaultValue的值一样,IDE将不会为这个属性生成代码;否则 ,IDE会自动在InitializeComponent中添加的代码”举例说明:Customer Component有个Age Property,声明如下[Description("Customer"s Age"), DefaultValue(20)]
public int Age
{
get { return _age; }
set { _age = value; }
}
有个窗体Form1,在Form1上贴有一个Customer类型的customer1,在设计时对Age设值为20,Form1的 InitializeComponent()为private void InitializeComponent()
{
this.customer1 = new Components.Customer();
//
// customer1
//
this.customer1.Address = null;
this.customer1.CreateTime = new System.DateTime(((long)(0)));
this.customer1.Id = null;
this.customer1.Sex = null;
}
如果在设计时对Age设值为40,Form1的InitializeComponent()为private void InitializeComponent()
{
this.customer1 = new Components.Customer();
//
// customer1
//
this.customer1.Address = null;
this.customer1.Age = 40;
this.customer1.CreateTime = new System.DateTime(((long)(0)));
this.customer1.Id = null;
this.customer1.Sex = null;
}
第二种情况比第一种多了句this.customer1.Age = 40;本来这章准备讲Component Designer的,但是在第3章的评论中chnking朋友问我,用户自定义 Property Editor中如何调试的问题,我原来在开发Component的过程都是用MessageBox来弹出信息,但是 lichdr提出了个更好的办法,监视进程,这样就能对用户自定义的Property Editor进行调试,我在vs 6.0里用这种方法调试过,但是在.net环境上我从来我想到过,我想很多朋友在开发过程也可能会遇到这 样的问题,至少我是遇到了,而且走了很多的弯路,所以把它作为单独的一章进行讲解下,在这里再次谢 谢lichdr。