VB .NET • Cache Reflection Metadata for Performance
Listing 1. This class's shared members act as a cache for its instances, each of which holds metadata about a single call object or row object.
Friend Class ReflectionCache
Private Shared _Instances As Dictionary(Of Type, _
              ReflectionCache)  = New Dictionary(Of Type, _
            Public  Shared Function CreateInstance(ByVal ForType As _
                          Type)  As ReflectionCache
                        If  Not _Instances.ContainsKey(ForType) Then
                          _Instances.Add(ForType,  New ReflectionCache(ForType))
              Catch ex As  ArgumentException
                          '  This actually can happen in multithreaded scenarios: 
                          '  Thread A queries ContainsKey; Thread B queries 
                          '  ContainsKey; Thread A adds new item;
                          '  Thread B adds new item.
                                      End  Try
                          End  If
              Return  _Instances(ForType
            End  Function
            Private Sub  New(ByVal ForType As Type)
                          '  Read the type's members here
              End Sub
End Class