使用重写方法链接类继承

时间:2017-12-14 09:04:29

标签: c# .net visual-studio-2015

作为一个大框架的一部分(所以我不能发布MCVE)我试图inherit a couple of times隐藏类的用户必要的初始化,所以结构是

// internal base class
public class InternalBase
{
  // declared internal to avoid subclassing by user - visibility 
  // is handled in AssemblyInfo.cs so library can subclass
  internal InternalBase()
  {
  }

  public virtual void startup()
  {
    // perform necessary initialization
  }
}

// public base class the users should inherit from
public class PublicBase : InternalBase
{
  public override void startup()
  {
    // call base class to perform required init
    base.startup();

    // perform extra steps like check if init was performed correctly
  }
}

// user class trying to use the provided functionaly
public class Test : PublicBase
{
  public override void startup()
  {
    // this is put here by convention/template to ensure execution of
    // required init - if this could be avoided, even better
    base.startup();

    // users are allowed to put their own init here
    // perform user init code
  }
}

现在,只要我想进入base.startup()类中的Test,系统就会表现得很奇怪。其他方法中的断点未被击中。从某个完全不同的地方抛出异常,日志输出表明程序继续了一点。当抛出异常(类型来自框架)时,没有callstack。

原则上这是否有效,我怎么能提供这样的功能或调试我的东西?

0 个答案:

没有答案