开发者

Design Mode Preprocessor Directive Workaround

开发者 https://www.devze.com 2023-03-19 12:54 出处:网络
I know that there is no DESIGN, DESIGN_MODE, DESIGN_TIME, etc preprocessor directive value. Howev开发者_StackOverflow社区er, I need something that can do the trick. I can\'t use a normal If statement,

I know that there is no DESIGN, DESIGN_MODE, DESIGN_TIME, etc preprocessor directive value. Howev开发者_StackOverflow社区er, 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?


Try using:

if (this.DesignMode == true)
{    }
else
{    }


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.

Partial Class MyCustomControl : MyAbstractClass_FAKE_IMPL
{
  //your normal class
}

and

Partial Class MyAbstractClass_FAKE_IMPL : MyAbstractClass
{

  //let IDE autogenerate implementation code that you are always going to override in reality.

}
0

精彩评论

暂无评论...
验证码 换一张
取 消