| 1 | #Region "Microsoft.VisualBasic::bd1b61932166abf44c2d61f01664ae4a, Microsoft.VisualBasic.Core\Text\Xml\Models\ValueTuples\NamedValues.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 NamedValue |
| 35 | ' |
| 36 | ' Properties: name, text |
| 37 | ' |
| 38 | ' Constructor: (+2 Overloads) Sub New |
| 39 | ' Function: ToString |
| 40 | ' |
| 41 | ' Structure [Property] |
| 42 | ' |
| 43 | ' Properties: Comment, name, value |
| 44 | ' |
| 45 | ' Constructor: (+1 Overloads) Sub New |
| 46 | ' Function: ToString |
| 47 | ' |
| 48 | ' Structure NamedVector |
| 49 | ' |
| 50 | ' Properties: attributes, name, vector |
| 51 | ' |
| 52 | ' Constructor: (+2 Overloads) Sub New |
| 53 | ' Function: ToString |
| 54 | ' |
| 55 | ' |
| 56 | ' /********************************************************************************/ |
| 57 | |
| 58 | #End Region |
| 59 | |
| 60 | Imports System.Runtime.CompilerServices |
| 61 | Imports System.Xml.Serialization |
| 62 | Imports Microsoft.VisualBasic.ComponentModel.Collection.Generic |
| 63 | Imports Microsoft.VisualBasic.ComponentModel.DataSourceModel |
| 64 | Imports Microsoft.VisualBasic.ComponentModel.DataSourceModel.Repository |
| 65 | Imports Microsoft.VisualBasic.Language |
| 66 | |
| 67 | Namespace Text.Xml.Models |
| 68 | |
| 69 | ''' <summary> |
| 70 | ''' 键值对集合的键值<see cref="text"/>可能是一大段文本 |
| 71 | ''' </summary> |
| 72 | <XmlType("data")> Public Class NamedValue |
| 73 | Implements INamedValue |
| 74 | Implements Value(Of String).IValueOf |
| 75 | |
| 76 | ''' <summary> |
| 77 | ''' The term category/key |
| 78 | ''' </summary> |
| 79 | ''' <returns></returns> |
| 80 | <XmlAttribute> |
| 81 | Public Property name As String Implements INamedValue.Key |
| 82 | ''' <summary> |
| 83 | ''' The term value |
| 84 | ''' </summary> |
| 85 | ''' <returns></returns> |
| 86 | <XmlText> |
| 87 | Public Property text As String Implements Value(Of String).IValueOf.Value |
| 88 | |
| 89 | Sub New(name$, value$) |
| 90 | Me.name = name |
| 91 | Me.text = value |
| 92 | End Sub |
| 93 | |
| 94 | Sub New() |
| 95 | End Sub |
| 96 | |
| 97 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
| 98 | Public Overrides Function ToString() As String |
| 99 | Return $"{name}: {text}" |
| 100 | End Function |
| 101 | End Class |
| 102 | |
| 103 | ''' <summary> |
| 104 | ''' Property Info (Property Name and Property Value). |
| 105 | ''' (和<see cref="NamedValue"/>所不同的是,这个对象之中的键值对集合的键值都是小段字符串) |
| 106 | ''' </summary> |
| 107 | Public Structure [Property] : Implements INamedValue |
| 108 | |
| 109 | <XmlAttribute> Public Property name As String Implements INamedValue.Key |
| 110 | <XmlAttribute> Public Property value As String |
| 111 | <XmlText> |
| 112 | Public Property Comment As String |
| 113 | |
| 114 | Sub New(name$, value$, comment$) |
| 115 | Me.name = name |
| 116 | Me.value = value |
| 117 | Me.Comment = comment |
| 118 | End Sub |
| 119 | |
| 120 | Public Overrides Function ToString() As String |
| 121 | Return $"{name} = ""{value}""" |
| 122 | End Function |
| 123 | End Structure |
| 124 | |
| 125 | ''' <summary> |
| 126 | ''' 在这里不实现<see cref="IEnumerable(Of T)"/>是为了方便的实现XML序列化操作 |
| 127 | ''' </summary> |
| 128 | ''' <typeparam name="T"></typeparam> |
| 129 | Public Structure NamedVector(Of T) |
| 130 | Implements INamedValue |
| 131 | |
| 132 | <XmlAttribute> |
| 133 | Public Property name As String Implements IKeyedEntity(Of String).Key |
| 134 | Public Property vector As T() |
| 135 | ''' <summary> |
| 136 | ''' 在这里不使用字典是因为Xml序列化无法序列化字典对象 |
| 137 | ''' </summary> |
| 138 | ''' <returns></returns> |
| 139 | Public Property attributes As NamedValue() |
| 140 | |
| 141 | Sub New(namedCollection As NamedCollection(Of T)) |
| 142 | With namedCollection |
| 143 | name = .Name |
| 144 | vector = .Value |
| 145 | End With |
| 146 | End Sub |
| 147 | |
| 148 | Sub New(name$, vector As T()) |
| 149 | Me.name = name |
| 150 | Me.vector = vector |
| 151 | End Sub |
| 152 | |
| 153 | Public Overrides Function ToString() As String |
| 154 | Return name |
| 155 | End Function |
| 156 | End Structure |
| 157 | End Namespace |