Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 0.50 KB | None | 0 0
  1. Class TCache(Of K, V)
  2.     Inherits Dictionary(Of K, V)
  3.  
  4.     Private ReadOnly finder As Func(Of K, V)
  5.  
  6.     Sub New(finder As Func(Of K, V))
  7.         Me.finder = finder
  8.     End Sub
  9.  
  10.     Default Public Shadows ReadOnly Property Item(key As K) As V
  11.         Get
  12.             Dim value As V = Nothing
  13.             If Me.TryGetValue(key, value) Then Return value
  14.             value = Me.finder(key)
  15.             Me.Add(key, value)
  16.             Return value
  17.         End Get
  18.     End Property
  19.  
  20. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement