Modules/EDMI_ClientSuite/ClassControlPatcher.vb

41 lines
1.5 KiB
VB.net

''' <summary>
''' Applies Modifications to a certain type of controls
''' </summary>
''' <example>
''' Dim oGridPatcher = New ClassControlPatcher(Of GridControl)(Me)
''' oGridPatcher.
''' ProcessContainer(AddressOf ClassGridControl.DefaultGridSettings).
''' ProcessContainer(AddressOf ClassGridControl.ReadOnlyGridSettings).
''' ProcessControl(AddressOf ClassGridControl.CheckboxSelectGridSettings, GridNotAssignedToParent).
''' ProcessControl(AddressOf ClassGridControl.CheckboxSelectGridSettings, GridAssignedToParent)
''' </example>
''' <typeparam name="T">The control to Patch</typeparam>
Public Class ClassControlPatcher(Of T As Control)
Private ReadOnly _Container As Control
Public Sub New(Container As Control)
_Container = Container
End Sub
Public Function ProcessContainer(Action As Action(Of T)) As ClassControlPatcher(Of T)
Return ProcessContainer(_Container, Action)
End Function
Public Function ProcessControl(Action As Action(Of T), ByVal Control As Control) As ClassControlPatcher(Of T)
Action(Control)
Return Me
End Function
Private Function ProcessContainer(ByVal Container As Control, Action As Action(Of T)) As ClassControlPatcher(Of T)
For Each oControl As Control In Container.Controls
If oControl.[GetType]() = GetType(T) Then
Action(oControl)
Else
ProcessContainer(oControl, Action)
End If
Next
Return Me
End Function
End Class