microsoft-visualbasic-runtime/Net/DomainName.vb

78 lines
2.5 KiB
VB.net

#Region "Microsoft.VisualBasic::20eb6a49be8a01b85cb9eda823ee0cd1, 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