如题,项目中有些自定义控件,它们的基类都是control,其中有的继承了接口IUpdata,有的没有,我想在处理的时候把继承接口了的控件转化为接口来调用里面的属性和方法,该如何筛选出哪个控件继承了接口呢?我现在用了
try
{ IUpdata uc = (IUpdata)myControl;}
catch()
{}
尽管有异常不影响程序,可总感觉不好;我也用过IsSubclassOf(typeof(IUpdata)),也不行,因为系统认为他们是control的子类.大家有什么好的方法吗?
try
{ IUpdata uc = (IUpdata)myControl;}
catch()
{}
尽管有异常不影响程序,可总感觉不好;我也用过IsSubclassOf(typeof(IUpdata)),也不行,因为系统认为他们是control的子类.大家有什么好的方法吗?
本内容使用CSDN小秘书回复
每天回帖即可得10分可用分!
*************************************************[/align]
if(myControl is IUpdata)
{
IUpdata uc = (IUpdata)myControl;
uc.xxxx;
}第二种方法:
IUpdata uc = myControl as IUpdata;
if(uc != null)
{
uc.xxxx;
}