Abstract UserControl inheritance in Visual Studio designer

前端 未结 9 1355
广开言路
广开言路 2020-12-01 12:13
abstract class CustomControl : UserControl 
{
    protected abstract int DoStuff();
}

class DetailControl : CustomControl
{
    protected override int DoStuff()
            


        
9条回答
  •  春和景丽
    2020-12-01 12:35

    Another way to solve this is using pre-processing directives.

    #if DEBUG
      public class UserControlAdmonEntidad : UserControl, IAdmonEntidad
    #else
      public abstract class UserControlAdmonEntidad : UserControl, IAdmonEntidad
    #endif
      {
        ...
        #if DEBUG
        public virtual object DoSomething()
        {
            throw new NotImplementedException("This method must be implemented!!!");
        }
        #else
        public abstract object DoSomething();
        #endif
    
        ...
      }
    

    See this link for more information regarding this topic: Inheriting a Form from an Abstract Class (and Making it Work in the Designer)

    The same solution was also mentioned in this MSDN forum thread, in a briefer way: UserControl, Inherited Control, Abstract class, (C#)

    Maybe is not the cleaner solution, but it's still the shortest I have found.

提交回复
热议问题