|
Namespace Controls
' This implements the disposable pattern it is intended for use where you want to over-ride defaults within a specific context
'Using New ContextDefaults
' Defaults("key") = "New value"
' 'Create controls as normal
'End Using
Public Class ContextDefaults
Implements IDisposable, IDefaults
Private _save As IDefaults
Private _item As New MemoryDefaults
Sub New()
_save = mGlobal.Defaults
mGlobal.Defaults = Me
End Sub
Public Function Contains(key As String) As Boolean Implements IDefaults.Contains
Return _item.Contains(key)
End Function
Default Public Property Item(key As String) As Object Implements IDefaults.Item
Get
If _item.Contains(key) Then Return _item(key)
Return _save.Item(key)
End Get
Set(value As Object)
_item(key) = value
End Set
End Property
Public ReadOnly Property Keys As IEnumerable(Of String) Implements IDefaults.Keys
Get
Return _item.Keys
End Get
End Property
#Region "IDisposable Support"
Private disposedValue As Boolean
Protected Overridable Sub Dispose(disposing As Boolean)
If Not Me.disposedValue Then
If disposing Then
mGlobal.Defaults = _save
End If
End If
Me.disposedValue = True
End Sub
Public Sub Dispose() Implements IDisposable.Dispose
Dispose(True)
GC.SuppressFinalize(Me)
End Sub
#End Region
End Class
End Namespace
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I enjoy my wife, living in the woods, my 7 dogs, and learning new things. I like to play with UI stuff and model based coding.