有没有办法重铸现有的控件?
例如,如果我们循环控制树直到找到类型为的控件bob
(显然这里没有任何检查无限循环):
Control parentCtrl = this.parent;
do
(
if(parentCtrl.getType == typeof(bob)) { break; }
else { parentCtrl = parentCtrl.parent; }
) while (true)
// This is the bit...?
bob parentCtrl = (bob)parentCtrl; // <-- will not compile as `parentCtrl` has been defined already
我知道我可以做((bob)parentCtrl).ctrlSpecificAttribute = "whatever dude...";
但是懒惰,我想节省一些括号和击键。
唯一的解决方案是拥有单独的目标控件吗?
bob targetCtrl = (bob)parentCtrl;