A generic class for sorting lists in VB.NET.
Public Class Section
Inherits StandardProperties
Public SectionID As Integer = 0
Public BlahForeignKeyID As Integer = 0
Public OtherBlahForeignKeyID As Integer = 0
Public SectionSubName As String = ""
End Class
Public Class SectionChild
Inherits StandardProperties
Public GridSectionID As String = ""
Public SomeForeignKeyID As Integer = 0
Public SomeOtherForeignKeyID As Integer = 0
End Class
Public Class StandardProperties
Implements IComparable(Of StandardProperties)
#Region "Is Dirty"
Private columnInfoIsDirty As Boolean
Public Property IsDirty() As Boolean
Get
Return columnInfoIsDirty
End Get
Set(ByVal value As Boolean)
columnInfoIsDirty = value
End Set
End Property
#End Region
#Region "Is Flagged For Delete"
Private columnInfoIsFlaggedForDelete As Boolean
Public Property IsFlaggedForDelete() As Boolean
Get
Return columnInfoIsFlaggedForDelete
End Get
Set(ByVal value As Boolean)
If columnInfoIsFlaggedForDelete <> value Then
IsDirty = True
columnInfoIsFlaggedForDelete = value
End If
End Set
End Property
#End Region
#Region "Sort Order"
Private columnInfoSortOrder As Integer
Public Property SortOrder() As Integer
Get
Return columnInfoSortOrder
End Get
Set(ByVal value As Integer)
If columnInfoSortOrder <> value Then
IsDirty = True
columnInfoSortOrder = value
End If
End Set
End Property
#End Region
#Region "Description"
Private columnInfoDescription As String
Public Property Description() As String
Get
Return columnInfoDescription
End Get
Set(ByVal value As String)
If columnInfoDescription <> value Then
IsDirty = True
columnInfoDescription = value
End If
End Set
End Property
#End Region
#Region "Equals"
Public Overloads Function Equals(ByVal comparedTo As StandardProperties) As Boolean
If Me.SortOrder = comparedTo.SortOrder Then
Return True
End If
Return False
End Function
#End Region
#Region "Equals"
Public Overloads Function Equals(ByVal comparedTo As String) As Boolean
If Me.Description = comparedTo Then
Return True
End If
Return False
End Function
#End Region
#Region "Compare To"
Public Function CompareTo(ByVal comparedTo As StandardProperties) As Integer
Return Me.SortOrder.CompareTo(comparedTo.SortOrder)
End Function
#End Region
#Region "Compare To"
Public Function CompareTo(ByVal thisItem As String, ByVal comparedTo As String) As Integer
Return String.Compare(thisItem,comparedTo)
End Function
#End Region
End Class
Public Class StandardPropertiesComparer
#Region "Compare Sort Order"
Public Shared Function CompareSortOrder(ByVal thisItem As StandardProperties, ByVal comparedTo As StandardProperties) As Integer
Return thisItem.CompareTo(comparedTo)
End Function
#End Region
#Region "Compare Description"
Public Shared Function CompareDescription(ByVal thisItem As StandardProperties, ByVal comparedTo As StandardProperties) As Integer
Return thisItem.CompareTo(thisItem.Description, comparedTo.Description)
End Function
#End Region
End Class
Public Class SectionComparer
Inherits StandardPropertiesComparer
#Region "Compare Section Sub Name"
Public Shared Function CompareSectionSubName(ByVal thisItem As Section, ByVal comparedTo As Section) As Integer
Return String.Compare(thisItem.SectionSubName, comparedTo.SectionSubName)
End Function
#End Region
End Class