microsoft-visualbasic-runtime/test/TypeTest.vb

125 lines
3.6 KiB
VB.net
Raw Normal View History

2019-03-22 22:19:09 +08:00
#Region "Microsoft.VisualBasic::c51b77afc5700a358fae81d50471d531, 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:
' Module TypeTest
'
' Function: CharArray
'
' Sub: Main, test
'
' /********************************************************************************/
#End Region
Imports Microsoft.VisualBasic.Language
2019-03-21 19:25:10 +08:00
Imports Microsoft.VisualBasic.Serialization.JSON
Module TypeTest
Sub Main()
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
2019-03-22 22:19:09 +08:00