| 1 | #Region "Microsoft.VisualBasic::a98cc1f4fe646e19f766f0b16248f737, Microsoft.VisualBasic.Core\ComponentModel\ValuePair\NamedTuple.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 | ' Class NamedTuple |
| 35 | ' |
| 36 | ' Properties: Item1, Item2, Name |
| 37 | ' |
| 38 | ' Constructor: (+3 Overloads) Sub New |
| 39 | ' Function: AsTuple, ToString |
| 40 | ' |
| 41 | ' |
| 42 | ' /********************************************************************************/ |
| 43 | |
| 44 | #End Region |
| 45 | |
| 46 | Imports Microsoft.VisualBasic.ComponentModel.Collection.Generic |
| 47 | Imports Microsoft.VisualBasic.ComponentModel.DataSourceModel |
| 48 | Imports Microsoft.VisualBasic.ComponentModel.DataSourceModel.Repository |
| 49 | |
| 50 | Namespace ComponentModel |
| 51 | |
| 52 | Public Class NamedTuple(Of T) : Implements INamedValue |
| 53 | |
| 54 | Public Property Name As String Implements IKeyedEntity(Of String).Key |
| 55 | Public Property Item1 As T |
| 56 | Public Property Item2 As T |
| 57 | |
| 58 | Sub New() |
| 59 | End Sub |
| 60 | |
| 61 | Sub New(item1 As T, item2 As T) |
| 62 | Me.Item1 = item1 |
| 63 | Me.Item2 = item2 |
| 64 | End Sub |
| 65 | |
| 66 | Sub New(name$, item1 As T, item2 As T) |
| 67 | Me.New(item1, item2) |
| 68 | Me.Name = name |
| 69 | End Sub |
| 70 | |
| 71 | Public Function AsTuple() As NamedValue(Of (T, T)) |
| 72 | Return New NamedValue(Of (T, T)) With { |
| 73 | .Name = Name, |
| 74 | .Value = (Item1, Item2) |
| 75 | } |
| 76 | End Function |
| 77 | |
| 78 | Public Overrides Function ToString() As String |
| 79 | Return Name |
| 80 | End Function |
| 81 | End Class |
| 82 | End Namespace |