软件频道>程序开发>JavaVBVCDelphiC/C++Web开发微软专栏移动数据库程序人生软件工程|开发客
您现在的位置: 天极网 > 开发频道 > 组件编程之自定义属性编辑器的调试
全文

组件编程之自定义属性编辑器的调试

2006-03-20 14:46作者:mapserver出处:博客园责任编辑:方舟
  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的,但是有朋友问我,用户自定义Property Editor中如何调试的问题,我原来在开发Component的过程都是用MessageBox来弹出信息,但是友人提出了个更好的办法,监视进程,这样就能对用户自定义的Property Editor进行调试,我在vs 6.0里用这种方法调试过,但是在.net环境上我从来我想到过,我想很多朋友在开发过程也可能会遇到这样的问题,至少我是遇到了,而且走了很多的弯路,所以把它作为单独的一章进行讲解下。

  先打开一个vs 2005的IDE(IDE1),在IDE1中打开WindowsApplication9解决方案,在Components.Demo3.cs中设置如下断点

  再打开一个vs 2005的IDE(IDE2),在IDE1做如下的操作:



  在IDE2中打开WindowsApplication9解决方案,并对Demo3的Grade Property设值时,IDE1中会发生断点调试中断。

软件资讯·软件下载尽在天极软件

相关搜索:
关注此文读者还看过
热门关注
特别推荐
文章排行
本周
本月
最近更新
关于我们|About us|网站律师|天极服务|电子杂志|RSS订阅|加入我们|网站地图
TMG
Copyright (C) 1999-2009 Chinabyte.com, All Rights Reserved 版权所有 天极网络
商务联系、网站内容、合作建议:010-82657868
版权声明 在线提交意见反馈 渝ICP证B2-20030003号
经营性网站备案信息 网警备案 中国网站排名
天极传媒:天极网|比特网|IT专家网|IT商网|52PK游戏网|IT分众