78 lines
2.5 KiB
VB.net
78 lines
2.5 KiB
VB.net
#Region "Microsoft.VisualBasic::459def7e826a7a3a22e06a13c3ffe04b, Microsoft.VisualBasic.Core\Net\DomainName.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:
|
|
|
|
' Structure DomainName
|
|
'
|
|
' Properties: Domain, Invalid, TLD
|
|
'
|
|
' Constructor: (+1 Overloads) Sub New
|
|
' Function: ToString
|
|
'
|
|
'
|
|
' /********************************************************************************/
|
|
|
|
#End Region
|
|
|
|
Imports System.Runtime.CompilerServices
|
|
Imports Microsoft.VisualBasic.ComponentModel.Collection.Generic
|
|
|
|
Namespace Net
|
|
|
|
Public Structure DomainName : Implements IKeyValuePairObject(Of String, String)
|
|
|
|
Public Property Domain As String Implements IKeyValuePairObject(Of String, String).Key
|
|
''' <summary>
|
|
''' 顶级域名
|
|
''' </summary>
|
|
''' <returns></returns>
|
|
Public Property TLD As String Implements IKeyValuePairObject(Of String, String).Value
|
|
|
|
Public ReadOnly Property Invalid As Boolean
|
|
<MethodImpl(MethodImplOptions.AggressiveInlining)>
|
|
Get
|
|
Return (String.IsNullOrEmpty(Domain) OrElse String.IsNullOrEmpty(TLD))
|
|
End Get
|
|
End Property
|
|
|
|
Sub New(url As String)
|
|
Dim tokens As String() = TryParse(url).Split(CChar("."))
|
|
Domain = tokens(0)
|
|
TLD = tokens.Skip(1).JoinBy(".")
|
|
End Sub
|
|
|
|
Public Overrides Function ToString() As String
|
|
Return $"{Domain}.{TLD}"
|
|
End Function
|
|
End Structure
|
|
End Namespace
|