设计模式预处理器指令解决方法
我知道没有 DESIGN、DESIGN_MODE、DESIGN_TIME 等预处理器指令值。然而,我需要一些可以解决问题的东西。我无法使用普通的 If 语句,因为在我的例子中,我需要更改继承的类,以便控件在设计时正确呈现。如果不是,我将收到一个异常,因为继承的类是一个抽象类。
这就是我想要完成的任务:
Partial Class MyCustomControl
#If DesignMode Then
Inherits UserControl
#Else
Inherits WidgetControl
#End If
有什么建议吗?
I know that there is no DESIGN, DESIGN_MODE, DESIGN_TIME, etc preprocessor directive value. However, I need something that can do the trick. I can't use a normal If statement, because in my case I need to change the inherited class so that the control renders properly at design time. If not, I'll receive an exception due to the fact that the inherited class is an abstract class.
Here's what I'm looking to accomplish:
Partial Class MyCustomControl
#If DesignMode Then
Inherits UserControl
#Else
Inherits WidgetControl
#End If
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用:
Try using:
过去我创建了一个虚拟类作为中间人。有时 VS 仍然会弄清楚你在做什么并感到不安,但通常重新启动 IDE 就可以解决这个问题。
和
In the past I have created a dummy class as a go between. Sometimes VS will still figure out what you are doing and get upset, but normally restarting the IDE will solve that.
and