.NET组件编程(4) 用户自定义Property Editor的调试

        园子里的高人太多了,第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。
        下面我用第三章的源代码进行演示下:源代码下载
        先打开一个vs 2005的IDE(IDE1),在IDE1中打开WindowsApplication9解决方案,在Components.Demo3.cs中设置如下断点
        
        再打开一个vs 2005的IDE(IDE2),在IDE1做如下的操作:

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

转载于:https://www.cnblogs.com/mapserver/archive/2006/03/08/345918.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值