Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net类继承-重写的函数不会从其自己的类调用_.net_Wpf_Vb.net_Class_Dependency Properties - Fatal编程技术网

.net类继承-重写的函数不会从其自己的类调用

.net类继承-重写的函数不会从其自己的类调用,.net,wpf,vb.net,class,dependency-properties,.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 Overri

我的班级结构如下:

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
对于上下文:这些类用于定义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中,则会调用ReportGroup中的函数,即使我从ReportContent类中调用该函数也是如此

我需要帮助来确保MyFunction在从ReportContent调用时从ReportContent调用,在ReportGroup调用时从ReportGroup调用

编辑1:
我尝试将函数更改为protected而不是public-同样的问题

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

MyClass.MyFunction()

有人建议我不要使用继承来建模层次结构。也许可以改为使用合成。我不确定你所说的合成是什么意思。将关系建模为属性。它看起来不像
ReportContent
is-a
ReportSection
。我明白了-例如,我删除了类的其他内容-reportsection有7个mustoverride属性和方法,并且reportGroup与报表内容共享完全相同的类结构(许多属性)-它只更改了两个函数。