| 1 | #Region "Microsoft.VisualBasic::3ca518ee546699dc6dba1e361a681ba0, Microsoft.VisualBasic.Core\ComponentModel\ValuePair\GenericAbstract.vb" |
| 2 | |
| 3 | ' Author: |
| 4 | ' |
| 5 | ' asuka (amethyst.asuka@gcmodeller.org) |
| 6 | ' xie (genetics@smrucc.org) |
| 7 | ' xieguigang (xie.guigang@live.com) |
| 8 | ' |
| 9 | ' Copyright (c) 2018 GPL3 Licensed |
| 10 | ' |
| 11 | ' |
| 12 | ' GNU GENERAL PUBLIC LICENSE (GPL3) |
| 13 | ' |
| 14 | ' |
| 15 | ' This program is free software: you can redistribute it and/or modify |
| 16 | ' it under the terms of the GNU General Public License as published by |
| 17 | ' the Free Software Foundation, either version 3 of the License, or |
| 18 | ' (at your option) any later version. |
| 19 | ' |
| 20 | ' This program is distributed in the hope that it will be useful, |
| 21 | ' but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 22 | ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 23 | ' GNU General Public License for more details. |
| 24 | ' |
| 25 | ' You should have received a copy of the GNU General Public License |
| 26 | ' along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 27 | |
| 28 | |
| 29 | |
| 30 | ' /********************************************************************************/ |
| 31 | |
| 32 | ' Summaries: |
| 33 | |
| 34 | ' Interface IKeyValuePairObject |
| 35 | ' |
| 36 | ' Properties: Key, Value |
| 37 | ' |
| 38 | ' Interface IReadOnlyDataSource |
| 39 | ' |
| 40 | ' Properties: Key, Value |
| 41 | ' |
| 42 | ' Class KeyValuePairObject |
| 43 | ' |
| 44 | ' Properties: Key, Value |
| 45 | ' |
| 46 | ' Constructor: (+3 Overloads) Sub New |
| 47 | ' Function: CreateObject, ToString |
| 48 | ' |
| 49 | ' Class KeyValuePairData |
| 50 | ' |
| 51 | ' Properties: DataObject |
| 52 | ' |
| 53 | ' |
| 54 | ' /********************************************************************************/ |
| 55 | |
| 56 | #End Region |
| 57 | |
| 58 | Namespace ComponentModel.Collection.Generic |
| 59 | |
| 60 | ''' <summary> |
| 61 | ''' Defines a key/value pair that can be set or retrieved. |
| 62 | ''' </summary> |
| 63 | ''' <typeparam name="TKey"></typeparam> |
| 64 | ''' <typeparam name="TValue"></typeparam> |
| 65 | ''' <remarks></remarks> |
| 66 | Public Interface IKeyValuePairObject(Of TKey, TValue) |
| 67 | ''' <summary> |
| 68 | ''' Gets the key in the key/value pair. |
| 69 | ''' </summary> |
| 70 | ''' <value></value> |
| 71 | ''' <returns></returns> |
| 72 | ''' <remarks></remarks> |
| 73 | Property Key As TKey |
| 74 | ''' <summary> |
| 75 | ''' Gets the value in the key/value pair. |
| 76 | ''' </summary> |
| 77 | ''' <value></value> |
| 78 | ''' <returns></returns> |
| 79 | ''' <remarks></remarks> |
| 80 | Property Value As TValue |
| 81 | End Interface |
| 82 | |
| 83 | ''' <summary> |
| 84 | ''' Defines a key/value pair that only can be retrieved. |
| 85 | ''' </summary> |
| 86 | ''' <typeparam name="TValue"></typeparam> |
| 87 | ''' <remarks></remarks> |
| 88 | Public Interface IReadOnlyDataSource(Of TValue) |
| 89 | ReadOnly Property Key As String |
| 90 | ReadOnly Property Value As TValue |
| 91 | End Interface |
| 92 | |
| 93 | ''' <summary> |
| 94 | ''' Defines a key/value pair that can be set or retrieved. |
| 95 | ''' </summary> |
| 96 | ''' <typeparam name="TKey"></typeparam> |
| 97 | ''' <typeparam name="TValue"></typeparam> |
| 98 | ''' <remarks></remarks> |
| 99 | Public Class KeyValuePairObject(Of TKey, TValue) : Implements IKeyValuePairObject(Of TKey, TValue) |
| 100 | |
| 101 | ''' <summary> |
| 102 | ''' Gets the key in the key/value pair. |
| 103 | ''' </summary> |
| 104 | ''' <value></value> |
| 105 | ''' <returns></returns> |
| 106 | ''' <remarks></remarks> |
| 107 | Public Overridable Property Key As TKey Implements IKeyValuePairObject(Of TKey, TValue).Key |
| 108 | ''' <summary> |
| 109 | ''' Gets the value in the key/value pair. |
| 110 | ''' </summary> |
| 111 | ''' <value></value> |
| 112 | ''' <returns></returns> |
| 113 | ''' <remarks></remarks> |
| 114 | Public Overridable Property Value As TValue Implements IKeyValuePairObject(Of TKey, TValue).Value |
| 115 | |
| 116 | Sub New() |
| 117 | End Sub |
| 118 | |
| 119 | Sub New(KEY As TKey, VALUE As TValue) |
| 120 | Me.Key = KEY |
| 121 | Me.Value = VALUE |
| 122 | End Sub |
| 123 | |
| 124 | Sub New(raw As KeyValuePair(Of TKey, TValue)) |
| 125 | Key = raw.Key |
| 126 | Value = raw.Value |
| 127 | End Sub |
| 128 | |
| 129 | Public Overrides Function ToString() As String |
| 130 | Return String.Format("{0} -> {1}", Key.ToString, Value.ToString) |
| 131 | End Function |
| 132 | |
| 133 | Public Shared Function CreateObject(key As TKey, value As TValue) As KeyValuePairObject(Of TKey, TValue) |
| 134 | Return New KeyValuePairObject(Of TKey, TValue) With {.Key = key, .Value = value} |
| 135 | End Function |
| 136 | |
| 137 | Public Shared Widening Operator CType(args As Object()) As KeyValuePairObject(Of TKey, TValue) |
| 138 | If args.IsNullOrEmpty Then |
| 139 | Return New KeyValuePairObject(Of TKey, TValue) |
| 140 | End If |
| 141 | If args.Length = 1 Then |
| 142 | Return New KeyValuePairObject(Of TKey, TValue) With { |
| 143 | .Key = DirectCast(args(Scan0), TKey) |
| 144 | } |
| 145 | End If |
| 146 | |
| 147 | Return New KeyValuePairObject(Of TKey, TValue) With { |
| 148 | .Key = DirectCast(args(Scan0), TKey), |
| 149 | .Value = DirectCast(args(1), TValue) |
| 150 | } |
| 151 | End Operator |
| 152 | End Class |
| 153 | |
| 154 | Public Class KeyValuePairData(Of T) : Inherits KeyValuePairObject(Of String, String) |
| 155 | Implements IKeyValuePairObject(Of String, String) |
| 156 | |
| 157 | Public Property DataObject As T |
| 158 | End Class |
| 159 | End Namespace |