Advertisement
Guest User

Untitled

a guest
Apr 13th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Friend 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.             Item = Nothing
  13.             If Me.TryGetValue(key, Item) Then Return Item
  14.             Item = Me.finder(key)
  15.             Me.Add(key, Item)
  16.         End Get
  17.     End Property
  18.  
  19. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement