希望我能“复活”这个话题。我遇到了类似的问题,除了我需要一个共享属性来返回子名称...所以我......构造不起作用。 我知道,这被认为是不好的设计,但我没有更好的主意 - 除了一堆重复的代码... 我的目标是非常类似于OP的一个...如何获得“A”基类'XString属性没有instancinatig ...? (XD是为XMLDocument ...)
Public MustInherit Class MinMax
Protected Shared Property XString As String = ???
Public Shared Function isValid(value As String) As Boolean
Return min <= value <= max
End Function
Private Shared ReadOnly Property min As Double
Get
Return xd.SelectSingleNode(String.Format("FOEB/Restrictions/{0}", XString)).InnerText.Split("..")(0)
End Get
End Property
Private Shared ReadOnly Property max As Double
Get
Return xd.SelectSingleNode(String.Format("FOEB/Restrictions/{0}", XString)).InnerText.Split("..")(1)
End Get
End Property
End Class
类用法:
Public Class Restrictions
Public Class A
Inherits MinMax
End Class
Public Class B
Inherits MinMax
End Class
End Class
dim isOk as Boolean= Restrictions.A.isValid("10")
的correstonding XML
<?xml version="1.0" encoding="utf-8" ?>
<FOEB>
<Restrictions>
<A>1..21</A>
</Restrictions>
</FOEB>
因此,返回值应为TRUE
Xstring是受保护,因为我试图在孩子身上隐藏/重写 - 没有运气,所以这是真实的与此无关
来源
2015-03-29 09:14:41
dba
只是一个查询,我一直认为基础知道它的派生类总是不好的设计实践。那么这真的是你希望这样做的唯一方式吗? – bioskope 2009-04-17 22:43:12
我知道会出现,我相信有这样做的更好方法。我在使用自己的小ORM工具时使用它,并且根据派生类的名称对数据库做出了一些假设。 – Kjensen 2009-04-18 10:23:01