Imports System.Collections.ObjectModel

Public Structure IdNameStruct

   Private m_Id As Integer
   Public Property Id As Integer
      Get
         Return m_Id
      End Get
      Set(value As Integer)
         m_Id = value
      End Set
   End Property

   Private m_Name As String
   Public Property Name As String
      Get
         Return m_Name
      End Get
      Set(value As String)
         m_Name = value
      End Set
   End Property

   Sub New(Id As Integer, Name As String)
      m_Id = Id
      m_Name = Name
   End Sub

   Public Overrides Function ToString() As String
      Return Name
   End Function

   Public Shared Function IndFromId(Id As Integer, List As ObservableCollection(Of IdNameStruct)) As Integer
      For i = 0 To List.Count - 1
         If List(i).Id = Id Then Return i
      Next
      Return 0
   End Function
   Public Shared Function IndFromId(Id As Integer, List As List(Of IdNameStruct)) As Integer
      For i = 0 To List.Count - 1
         If List(i).Id = Id Then Return i
      Next
      Return 0
   End Function

   Public Shared Function IdFromInd(Ind As Integer, List As ObservableCollection(Of IdNameStruct)) As Integer
      Return List(Ind).Id
   End Function
   Public Shared Function IdFromInd(Ind As Integer, List As List(Of IdNameStruct)) As Integer
      Return List(Ind).Id
   End Function

   Public Shared Function IndFromId(Id As Integer, List As ObservableCollection(Of Object)) As Integer
      For i = 0 To List.Count - 1
         If TypeOf (List(i)) Is IdNameStruct AndAlso DirectCast(List(i), IdNameStruct).Id = Id Then
            Return i
         End If
      Next
      Return 0
   End Function
   Public Shared Function IndFromId(Id As Integer, List As List(Of Object)) As Integer
      For i = 0 To List.Count - 1
         If TypeOf (List(i)) Is IdNameStruct AndAlso DirectCast(List(i), IdNameStruct).Id = Id Then
            Return i
         End If
      Next
      Return 0
   End Function

   Public Shared Function IdFromInd(Ind As Integer, List As ObservableCollection(Of Object)) As Integer
      If TypeOf (List(Ind)) Is IdNameStruct Then
         Return DirectCast(List(Ind), IdNameStruct).Id
      End If
      Return 0
   End Function
   Public Shared Function IdFromInd(Ind As Integer, List As List(Of Object)) As Integer
      If TypeOf (List(Ind)) Is IdNameStruct Then
         Return DirectCast(List(Ind), IdNameStruct).Id
      End If
      Return 0
   End Function

   Public Shared Function IdFromName(Name As String, List As ObservableCollection(Of Object)) As Integer
      For i = 0 To List.Count - 1
         If DirectCast(List(i), IdNameStruct).Name = Name Then Return DirectCast(List(i), IdNameStruct).Id
      Next
      Return 0
   End Function
   Public Shared Function IdFromName(Name As String, List As List(Of Object)) As Integer
      For i = 0 To List.Count - 1
         If DirectCast(List(i), IdNameStruct).Name = Name Then Return DirectCast(List(i), IdNameStruct).Id
      Next
      Return 0
   End Function

End Structure
