microsoft-visualbasic-runtime/test/TypeTest.vb

151 lines
4.2 KiB
VB.net
Raw Normal View History

2019-11-10 15:16:27 +08:00
#Region "Microsoft.VisualBasic::309722185e7a73cc8dc96f3491126449, Microsoft.VisualBasic.Core\test\TypeTest.vb"
' Author:
'
' asuka (amethyst.asuka@gcmodeller.org)
' xie (genetics@smrucc.org)
' xieguigang (xie.guigang@live.com)
'
' Copyright (c) 2018 GPL3 Licensed
'
'
' GNU GENERAL PUBLIC LICENSE (GPL3)
'
'
' This program is free software: you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by
' the Free Software Foundation, either version 3 of the License, or
' (at your option) any later version.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' GNU General Public License for more details.
'
' You should have received a copy of the GNU General Public License
' along with this program. If not, see <http://www.gnu.org/licenses/>.
' /********************************************************************************/
' Summaries:
' Enum FlagCombos
'
'
'
'
'
'
' Module TypeTest
'
' Function: CharArray
'
' Sub: descriptionTest, Main, patternMatch, test
'
' /********************************************************************************/
2019-03-22 22:19:09 +08:00
#End Region
Imports System.ComponentModel
2019-03-22 22:19:09 +08:00
Imports Microsoft.VisualBasic.Language
2019-03-21 19:25:10 +08:00
Imports Microsoft.VisualBasic.Serialization.JSON
Public Enum FlagCombos
A = 2
B = 4
<Description("The last one")> C = 8
End Enum
2019-03-21 19:25:10 +08:00
Module TypeTest
Sub descriptionTest()
2019-03-21 19:25:10 +08:00
Call Console.WriteLine(FlagCombos.A.Description)
Call Console.WriteLine(FlagCombos.B.Description)
Call Console.WriteLine(FlagCombos.C.Description)
Call Console.WriteLine((FlagCombos.A Or FlagCombos.B Or FlagCombos.C).Description)
Pause()
End Sub
Sub Main()
Call descriptionTest()
2019-03-23 03:16:16 +08:00
Call patternMatch()
2019-03-21 19:25:10 +08:00
Call test()
2019-03-23 03:16:16 +08:00
Dim o As [Variant](Of String, Integer(), Char())
2019-03-21 19:25:10 +08:00
o = "string"
Console.WriteLine(CStr(o))
Console.WriteLine(o Like GetType(String))
Console.WriteLine(o Like GetType(Integer()))
Console.WriteLine(o Like GetType(Char()))
o = {1, 2, 1231, 31, 23, 12}
Console.WriteLine(CType(o, Integer()).GetJson)
Console.WriteLine(o Like GetType(String))
Console.WriteLine(o Like GetType(Integer()))
Console.WriteLine(o Like GetType(Char()))
o = {"f"c, "s"c, "d"c, "f"c, "s"c, "d"c, "f"c, "s"c, "d"c, "f"c, "s"c, "d"c, "f"c}
Console.WriteLine(CType(o, Char()).GetJson)
Console.WriteLine(o Like GetType(String))
Console.WriteLine(o Like GetType(Integer()))
Console.WriteLine(o Like GetType(Char()))
Pause()
End Sub
2019-03-23 03:16:16 +08:00
Sub patternMatch()
Dim src As [Variant](Of String(), Integer(), Byte()) = {23, 4, 2342, 42}
Select Case src
Case src Like GetType(String())
Console.WriteLine("is string")
Case src Like GetType(Integer())
Console.WriteLine("is integer")
Case src Like GetType(Byte())
Console.WriteLine("is bytes")
Case Else
Throw New Exception
End Select
Pause()
End Sub
2019-03-21 19:25:10 +08:00
Sub test()
2019-03-23 03:16:16 +08:00
Dim chars As [Variant](Of Char(), Integer())
2019-03-21 19:25:10 +08:00
chars = CharArray("Hello world!", False)
Console.WriteLine(CType(chars, Char()).GetJson)
Console.WriteLine(chars Like GetType(Integer()))
Console.WriteLine(chars Like GetType(Char()))
chars = CharArray("Hello world!", True)
Console.WriteLine(CType(chars, Integer()).GetJson)
Console.WriteLine(chars Like GetType(Integer()))
Console.WriteLine(chars Like GetType(Char()))
Pause()
End Sub
2019-03-23 03:16:16 +08:00
Public Function CharArray(s As String, ascii As Boolean) As [Variant](Of Char(), Integer())
2019-03-21 19:25:10 +08:00
If ascii Then
Return s.Select(Function(c) AscW(c)).ToArray
Else
Return s.ToArray
End If
End Function
End Module