我知道没有DESIGN,DESIGN_MODE,DESIGN_TIME等预处理器指令值。但是,我需要能够做到这一点的东西。我不能使用普通的If语句,因为在我的情况下我需要更改继承的类,以便控件在设计时正确呈现。如果没有,我将收到一个异常,因为继承的类是一个抽象类。
以下是我要完成的事情:
Partial Class MyCustomControl
#If DesignMode Then
Inherits UserControl
#Else
Inherits WidgetControl
#End If
有什么建议吗?
答案 0 :(得分:0)
尝试使用:
if (this.DesignMode == true)
{ }
else
{ }
答案 1 :(得分:0)
在过去,我创建了一个虚拟课程。有时VS仍然会弄清楚你在做什么并感到沮丧,但通常重启IDE会解决这个问题。
Partial Class MyCustomControl : MyAbstractClass_FAKE_IMPL
{
//your normal class
}
和
Partial Class MyAbstractClass_FAKE_IMPL : MyAbstractClass
{
//let IDE autogenerate implementation code that you are always going to override in reality.
}