Advertisement
maxhodges0

IEquatable

Oct 15th, 2012
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Class FedExShipmentCollection
  2.     Inherits CollectionBase
  3.  
  4.     Default Property Item(ByVal Index As Integer) As FedExShipment
  5.         Get
  6.             Return CType(List.Item(Index), FedExShipment)
  7.         End Get
  8.         Set(ByVal Value As FedExShipment)
  9.             List.Item(Index) = Value
  10.         End Set
  11.     End Property
  12.  
  13.     Function Add(ByVal Item As FedExShipment) As Integer
  14.         Return List.Add(Item)
  15.     End Function
  16. End Class
  17.  
  18. Class FedExShipmentLineItem
  19.     Implements System.IEquatable(Of FedExShipmentLineItem)
  20.     Private _itemDescription As System.String
  21.     Private _countryOfOrigin As System.String
  22.     Private _FedExShipment As FedExShipment
  23.  
  24.     Public Shadows Function Equals(ByVal other As FedExShipmentLineItem) As Boolean Implements IEquatable(Of FedExShipmentLineItem).Equals
  25.         If other Is Nothing Then Return False
  26.         If Me Is other Then Return True
  27.         Return Me.ItemDescription.Equals(other.ItemDescription) AndAlso Me.CountryOfOriginCode.Equals(other.CountryOfOriginCode)
  28.     End Function
  29.  
  30.     Public Overrides Function GetHashCode() As Integer
  31.         Dim hashItemDescription As Integer = If(ItemDescription Is Nothing, 0, ItemDescription.GetHashCode)
  32.         Dim hashCountyOfOrigin As Integer = If(CountryOfOriginCode Is Nothing, 0, CountryOfOriginCode.GetHashCode)
  33.         Return hashCountyOfOrigin Xor hashItemDescription
  34.     End Function
  35.  
  36.     Public Sub New(ByRef FedExShipment As FedExShipment)
  37.         _FedExShipment = FedExShipment
  38.         FedExShipment.AddLineItem(Me)
  39.     End Sub
  40.  
  41.     Public Property ItemDescription As System.String
  42.         Get
  43.             Return _itemDescription
  44.         End Get
  45.         Set(ByVal Value As System.String)
  46.             _itemDescription = Value
  47.         End Set
  48.     End Property
  49.  
  50.     Public Property CountryOfOriginCode As System.String
  51.         Get
  52.             Return _countryOfOrigin
  53.         End Get
  54.         Set(ByVal Value As System.String)
  55.             'If Value.Length <> 2 Then Throw New ArgumentException("CountryOfOriginCode must be 2 characters.")
  56.            _countryOfOrigin = Value
  57.         End Set
  58.     End Property
  59. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement