Именование классов иногда сложно. Как вы думаете, как должно выглядеть название класса?Каким должно быть имя этого класса?
Первоначально я создал класс для использования в качестве кеша, но может видеть, что его могут иметь другие виды использования. Пример кода для использования класса.
Dim cache = New NamePendingDictionary(Of String, Sample)
Dim value = cache("a", Function() New Sample())
И вот класс, которому нужно имя.
' <summary> '
' Enhancement of <see cref="System.Collections.Generic.Dictionary"/>. See the Item property '
' for more details. '
' </summary> '
' <typeparam name="TKey">The type of the keys in the dictionary.</typeparam> '
' <typeparam name="TValue">The type of the values in the dictionary.</typeparam> '
Public Class NamePendingDictionary(Of TKey, TValue)
Inherits Dictionary(Of TKey, TValue)
Delegate Function DefaultValue() As TValue
' <summary> '
' Gets or sets the value associated with the specified key. If the specified key does not exist '
' then <paramref name="createDefaultValue"/> is invoked and added to the dictionary. The created '
' value is then returned. '
' </summary> '
' <param name="key">The key of the value to get.</param> '
' <param name="createDefaultValue"> '
' The delegate to invoke if <paramref name="key"/> does not exist in the dictionary. '
' </param> '
' <exception cref="T:System.ArgumentNullException"><paramref name="key" /> is null.</exception> '
Default Public Overloads ReadOnly Property Item(ByVal key As TKey, ByVal createDefaultValue As DefaultValue) As TValue
Get
Dim value As TValue
If createDefaultValue Is Nothing Then
Throw New ArgumentNullException("createValue")
End If
If Not Me.TryGetValue(key, value) Then
value = createDefaultValue.Invoke()
Me.Add(key, value)
End If
Return value
End Get
End Property
End Class
EDIT: По рекомендации Абеля я назвал класс ValueCache.
Markdown действительно сосет при подсветке VB. – kennytm
@KennyTM: что помогает использовать комментарии VB с одинарными кавычками, а также заканчивать каждую строку одной цитатой (немного работы, я знаю). MarkDown рассмотрит комментарии строки, но просмотр кода становится намного понятнее (больше не выделяется внутренними комментариями) – Abel
@Abel. Спасибо за информацию о форматировании кода VB в MarkDown. –