如何为每个继承的类创建一个共享变量?

时间:2019-05-12 11:23:07

标签: vb.net shared system.reflection

说基是基类

我想在Base派生的所有类上共享一个变量。但是,每个派生类都有其自己的共享变量。

这是怎么实现的?

Private Shared _tableOfCurrencyDictionary As Dictionary(Of String, Dictionary(Of String, BaseQuoteandBaseQuote))

Protected Property _tableOfCurrency As Dictionary(Of String, BaseQuoteandBaseQuote)
    Get
        Dim className = Me.GetType().Name
        If _tableOfCurrencyDictionary.ContainsKey(className) Then
            Return _tableOfCurrencyDictionary(className)
        Else
            Return Nothing
        End If
    End Get
    Set(value As Dictionary(Of String, BaseQuoteandBaseQuote))
        Dim className = Me.GetType().Name
        _tableOfCurrencyDictionary(className) = value
    End Set
End Property

还有更好的方法吗?

0 个答案:

没有答案