.net类继承 - 覆盖的函数不会从它自己的类中调用

时间:2014-03-17 16:46:12

标签: .net wpf vb.net class dependency-properties

我有类似的类结构:

Class ReportSection
    ...
End Class

Class ReportContent
     Inhertis ReportSection
     ...
     Public Overridable Function MyFunction() as Boolean
End Class

Class ReportGrouping
     Inhertis ReportContent
     ...
     Public Overrides Function MyFunction() as Boolean
End Class

For Context:这些类用于在wpf项目中定义依赖项属性,其中ReportGrouping是ReportContent的依赖项属性。以下是层次结构的简化示例:

<kr:ReportContent>
  <kr:ReportContent.Body>
    <kr:ReportGrouping>
      <kr:ReportGrouping.Body>
      </kr:ReportGrouping.Body >
    </kr:ReportGrouping >
  </kr:ReportContent.Body >
</kr:ReportContent >

问题:

问题在于,如果我将ReportGroup添加到ReportContent,那么即使我在ReportContent类中调用该函数,也会调用ReportGroup中的Function。

我需要帮助以确保在从ReportContent调用时从ReportContent调用MyFunction,并在ReportGroup调用它时从ReportGroup调用。

编辑1:

我尝试将功能更改为受保护而不是公共 - 同样的问题

1 个答案:

答案 0 :(得分:2)

如果要强制它调用当前类(而不是派生类)定义的方法版本,则需要使用MyClass关键字,例如:

MyClass.MyFunction()