| 1 | #Region "Microsoft.VisualBasic::decd1d16f8bd8664b6efe4343e8c06ea, Microsoft.VisualBasic.Core\Language\BaseClass.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 IClassObject |
| 35 | ' |
| 36 | ' Properties: Extension |
| 37 | ' |
| 38 | ' Class BaseClass |
| 39 | ' |
| 40 | ' Properties: Extension |
| 41 | ' |
| 42 | ' Function: __toString, ReadProperty, ToString |
| 43 | ' Operators: (+2 Overloads) IsFalse, (+2 Overloads) IsTrue, (+2 Overloads) Not |
| 44 | ' |
| 45 | ' |
| 46 | ' /********************************************************************************/ |
| 47 | |
| 48 | #End Region |
| 49 | |
| 50 | Imports System.Web.Script.Serialization |
| 51 | Imports System.Xml.Serialization |
| 52 | Imports Microsoft.VisualBasic.ComponentModel.DataSourceModel |
| 53 | Imports Microsoft.VisualBasic.Serialization.JSON |
| 54 | |
| 55 | Namespace Language |
| 56 | |
| 57 | 'Public Module ClassAPI |
| 58 | |
| 59 | ' ''' <summary> |
| 60 | ' ''' Example of the extension property in VisualBasic |
| 61 | ' ''' </summary> |
| 62 | ' ''' <typeparam name="T"></typeparam> |
| 63 | ' ''' <param name="x"></param> |
| 64 | ' ''' <returns></returns> |
| 65 | ' <Extension> |
| 66 | ' Public Function Uid(Of T As ClassObject)(x As T) As PropertyValue(Of Long) |
| 67 | ' Return PropertyValue(Of Long).Read(Of T)(x, NameOf(Uid)) |
| 68 | |
| 69 | ' ' Just copy this statement without any big modification. just modify the generics type constraint. |
| 70 | ' Return PropertyValue(Of Long).Read(Of T)(x, MethodBase.GetCurrentMethod) |
| 71 | ' End Function |
| 72 | 'End Module |
| 73 | |
| 74 | ''' <summary> |
| 75 | ''' The base class object in VisualBasic |
| 76 | ''' </summary> |
| 77 | Public Interface IClassObject |
| 78 | |
| 79 | ''' <summary> |
| 80 | ''' The extension property.(为了节省内存的需要,这个附加属性尽量不要被自动初始化) |
| 81 | ''' </summary> |
| 82 | ''' <returns></returns> |
| 83 | Property Extension As ExtendedProps |
| 84 | End Interface |
| 85 | |
| 86 | ''' <summary> |
| 87 | ''' The base class object in VisualBasic language |
| 88 | ''' </summary> |
| 89 | Public Class BaseClass : Implements IClassObject |
| 90 | |
| 91 | ''' <summary> |
| 92 | ''' The extension property.(为了节省内存的需要,这个附加属性尽量不要被自动初始化) |
| 93 | ''' </summary> |
| 94 | ''' <returns></returns> |
| 95 | ''' <remarks> |
| 96 | ''' Dummy field for solve the problem of xml serialization >>>simpleContent<<< |
| 97 | ''' |
| 98 | ''' http://stackoverflow.com/questions/2501466/xmltext-attribute-in-base-class-breakes-serialization |
| 99 | ''' |
| 100 | ''' So I think you could make it work by adding a dummy property or field that you never |
| 101 | ''' use in the ``LookupItem`` class. |
| 102 | ''' If you're never assign a value to it, it will remain null and will not be serialized, |
| 103 | ''' but it will prevent your class from being treated as simpleContent. I know it's a |
| 104 | ''' dirty workaround, but I see no other easy way... |
| 105 | ''' </remarks> |
| 106 | <XmlIgnore> |
| 107 | <ScriptIgnore> |
| 108 | <SoapIgnore> |
| 109 | Public Overridable Property Extension As ExtendedProps Implements IClassObject.Extension |
| 110 | |
| 111 | ''' <summary> |
| 112 | ''' Get dynamics property value. |
| 113 | ''' </summary> |
| 114 | ''' <typeparam name="T"></typeparam> |
| 115 | ''' <param name="name"></param> |
| 116 | ''' <returns></returns> |
| 117 | Public Function ReadProperty(Of T)(name As String) As PropertyValue(Of T) |
| 118 | Return PropertyValue(Of T).Read(Me, name) |
| 119 | End Function |
| 120 | |
| 121 | ''' <summary> |
| 122 | ''' Default is display the json value of the object class |
| 123 | ''' </summary> |
| 124 | ''' <returns></returns> |
| 125 | Public Overrides Function ToString() As String |
| 126 | Return [GetType].GetObjectJson(Me, False) |
| 127 | End Function |
| 128 | |
| 129 | ''' <summary> |
| 130 | ''' String source for operator <see cref="BaseClass.Operator &(BaseClass, String)"/> |
| 131 | ''' </summary> |
| 132 | ''' <returns>Default is using <see cref="ToString"/> method as provider</returns> |
| 133 | Protected Friend Overridable Function __toString() As String |
| 134 | Return ToString() |
| 135 | End Function |
| 136 | |
| 137 | ''' <summary> |
| 138 | ''' Contact this class object with other string value |
| 139 | ''' </summary> |
| 140 | ''' <param name="x"></param> |
| 141 | ''' <param name="s"></param> |
| 142 | ''' <returns></returns> |
| 143 | Public Shared Operator &(x As BaseClass, s As String) As String |
| 144 | Return x.__toString & s |
| 145 | End Operator |
| 146 | |
| 147 | ''' <summary> |
| 148 | ''' Contact this class object with other string value |
| 149 | ''' </summary> |
| 150 | ''' <param name="s"></param> |
| 151 | ''' <param name="x"></param> |
| 152 | ''' <returns></returns> |
| 153 | Public Shared Operator &(s As String, x As BaseClass) As String |
| 154 | Return s & x.__toString |
| 155 | End Operator |
| 156 | |
| 157 | Public Shared Operator IsTrue(x As BaseClass) As Boolean |
| 158 | Return Not x Is Nothing |
| 159 | End Operator |
| 160 | |
| 161 | Public Shared Operator IsFalse(x As BaseClass) As Boolean |
| 162 | Return x Is Nothing |
| 163 | End Operator |
| 164 | |
| 165 | Public Shared Operator Not(x As BaseClass) As Boolean |
| 166 | If x Is Nothing Then |
| 167 | Return True |
| 168 | Else |
| 169 | Return False |
| 170 | End If |
| 171 | End Operator |
| 172 | End Class |
| 173 | End Namespace |