我在两个独立的库中有两个类(一个 VB,一个 C#):
Public Class Item
...
Public Overridable ReadOnly Property TotalPrice() As String
Get
Return FormatCurrency(Price + SelectedOptionsTotal())
End Get
End Property
End Class
和
public class DerivedItem : Item {
...
public new Decimal TotalPrice
{
get { return Price + OptionsPrice; }
}
}
如您所见,DerivedItem.TotalPrice
阴影遮住了Item.TotalPrice
属性。但是,当尝试检索该DerivedItem.TotalPrice
值时,我仍在获取基础对象的TotalPrice
值。
为什么DerivedItem
' 的属性没有被归还?
编辑
我真的发现了问题!我在通过 AJAX 返回的 JSON 字符串中得到了错误的值。事实证明,TotalPrice
它被正确返回,它只是被稍后在 JSON 字符串中进行的阴影属性调用覆盖。那么,我的新问题是如何防止阴影属性被序列化?
(此问题已在此处重新调整范围)