30-07-16, 07:57 PM
بعد وضوح الأمر بشكل جيد هنا نحتاج ان نقوم بالتعديل علي الكلاس الأصلي قليلا حتي نستطيع مقارنة الروابط عند الحاجة إلي ذلك و الهدف هنا أن نتجنب أن يوجد رابط يحمل نفس الإسم
في المشاركات التالية سأكتب لك بقية الكود
كود :
Imports System.Globalization
Public Class BrowserHistory
Implements ICloneable, IComparable
#Region "Field"
Private historyName As String
Private historyDate As String
#End Region
#Region "Constructor"
Public Sub New()
Me.New(CType(Nothing, String), CType(Nothing, DateTime))
End Sub
Public Sub New(historyLinkNname As String, historyDateTime As DateTime)
historyName = historyLinkNname
historyDate = historyDateTime
End Sub
#End Region
#Region "Property"
Public Property HistroryLink As String
Get
Return historyName
End Get
Set(value As String)
historyName = value
End Set
End Property
Public Property HistoryDateTime As DateTime
Get
Return historyDate
End Get
Set(value As DateTime)
historyDate = value
End Set
End Property
#End Region
#Region "Method"
Public Function Clone() As Object Implements ICloneable.Clone
Return MyBase.MemberwiseClone()
End Function
Public Function CompareTo(obj As Object) As Integer Implements IComparable.CompareTo
If TypeOf obj Is BrowserHistory Then
Dim history As BrowserHistory = CType(obj, BrowserHistory)
If Me.HistoryDateTime > history.HistoryDateTime Then
Return 1
End If
If Me.HistoryDateTime < history.HistoryDateTime Then
Return -1
End If
End If
Return 0
End Function
Public Shared Operator =(firstHistory As BrowserHistory, secondHistroy As BrowserHistory) As Boolean
Return firstHistory.Equals(secondHistroy)
End Operator
Public Shared Operator <>(firstHistory As BrowserHistory, secondHistroy As BrowserHistory) As Boolean
Return Not (firstHistory Is secondHistroy)
End Operator
Public Shared Operator <(firstHistory As BrowserHistory, secondHistroy As BrowserHistory) As Boolean
Return firstHistory.CompareTo(secondHistroy) < 0
End Operator
Public Shared Operator >(firstHistory As BrowserHistory, secondHistroy As BrowserHistory) As Boolean
Return firstHistory.CompareTo(secondHistroy) > 0
End Operator
Public Shared Function HistoryToDateTime(history As BrowserHistory) As DateTime
If history IsNot Nothing Then
Return history.HistoryDateTime
' You may use the below code instead
' You may add more paramters to the returned value based on your requirements
'Return New DateTime(CType(history.HistoryDateTime.Day, Integer), CType(history.HistoryDateTime.Hour, Integer), CType(history.HistoryDateTime.Minute, Integer))
End If
Return Nothing
End Function
Public Shared Function HistoryToList(history As BrowserHistory) As List(Of String)
If history IsNot Nothing Then
Return New List(Of String) From {history.historyName, history.HistoryDateTime.ToString}
End If
Return Nothing
End Function
Public Shared Function HistoryToLink(history As BrowserHistory) As String
If history IsNot Nothing Then
Return history.HistroryLink
End If
Return CType(Nothing, String)
End Function
Public Shared Function HistoryToUri(history As BrowserHistory) As Uri
If history IsNot Nothing Then
Return New Uri(history.HistroryLink)
End If
Return Nothing
End Function
Public Overrides Function GetHashCode() As Integer
Return Me.HistoryDateTime.GetHashCode()
End Function
Public Overrides Function Equals(obj As Object) As Boolean
Return TypeOf obj Is BrowserHistory AndAlso Me.Equals(CType(obj, BrowserHistory))
End Function
Public Overloads Function Equals(history As BrowserHistory) As Boolean
Return Me.HistoryDateTime.Equals(history.HistoryDateTime)
End Function
Public Overrides Function ToString() As String
Return String.Concat(New String() {Me.historyName.ToString(CultureInfo.CurrentCulture), Me.HistoryDateTime.ToString(CultureInfo.CurrentCulture)})
End Function
#End Region
End Classفي المشاركات التالية سأكتب لك بقية الكود

