Namespace Data.List
Public Class Column
Implements IDisposable
' Default use a function GetValue. It also supports simple value setting with SetFixedDefault
' So values can be defaulted to things like Today, New Guid(), NextSequence, etc
#Region " Private fields "
Private _parent As DataList
Private _name As String = String.Empty
Private _fixedDefault As Object = String.Empty
Private _default As GetValue = AddressOf ADefault
Delegate Function GetValue() As Object
#End Region
Sub New(parent As DataList, name As String, Optional header As String = "", Optional type As Type = Nothing, Optional width As Integer = 0, Optional isRequired As Boolean = False)
If parent Is Nothing Then Throw New InvalidConstraintException("parent is required")
_parent = parent
_name = name
If type Is Nothing Then type = GetType(String)
Me.Type = type
If header = String.Empty Then Me.Header = _name Else Me.Header = header
Me.Width = width
Me.IsRequired = isRequired
End Sub
Sub New(parent As DataList, name As String, defaultValue As Object, Optional header As String = "", Optional type As Type = Nothing, Optional width As Integer = 0, Optional isRequired As Boolean = False)
If parent Is Nothing Then Throw New InvalidConstraintException("parent is required")
_parent = parent
_name = name
If type Is Nothing Then type = String.Empty.GetType
Me.Type = type
If header = String.Empty Then Me.Header = _name Else Me.Header = header
Me.Width = width
Me.IsRequired = isRequired
Call SetFixedDefault(defaultValue)
End Sub
Public Sub SetFixedDefault(value As Object)
_fixedDefault = value
Me.DefaultValue = AddressOf GetFixedDefault
End Sub
Public Property DefaultValue As GetValue
Get
Return _default
End Get
Set(value As GetValue)
_default = value
End Set
End Property
Public ReadOnly Property List As DataList
Get
Return _parent
End Get
End Property
Public ReadOnly Property Name As String
Get
Return _name
End Get
End Property
Public Property Header As String
Public Property Width As String
Public Property IsRequired As Boolean
Public Property Type As Type
Public ReadOnly Property Index As Integer
Get
Return _parent.Columns.Index(_name)
End Get
End Property
#Region " Support routines "
Private Function GetFixedDefault() As Object
Return _fixedDefault
End Function
Private Function ADefault() As Object
Return Nothing
End Function
Private disposedValue As Boolean ' To detect redundant calls
Protected Overridable Sub Dispose(disposing As Boolean)
If Not Me.disposedValue Then
If disposing Then
_parent = Nothing
_name = String.Empty
_fixedDefault = Nothing
_default = Nothing
End If
End If
Me.disposedValue = True
End Sub
Public Sub Dispose() Implements IDisposable.Dispose
' Do not change this code. Put cleanup code in Dispose(disposing As Boolean) above.
Dispose(True)
GC.SuppressFinalize(Me)
End Sub
#End Region
End Class
End Namespace