1 #Region "Microsoft.VisualBasic::cde87599de7da7c223148346a18815de, Microsoft.VisualBasic.Core\CommandLine\Reflection\CLIToken.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     '     Class CLIToken
35     
36     '         Properties: Name
37     
38     '         Constructor: (+1 OverloadsSub New
39     '         FunctionToString
40     
41     '     Class Argv
42     
43     '         Properties: IsOptional, Type
44     
45     '         Constructor: (+1 OverloadsSub New
46     '         FunctionToString
47     
48     '     Class Prefix
49     
50     '         Properties: Value
51     
52     '         Constructor: (+1 OverloadsSub New
53     '         FunctionToString
54     
55     
56     ' /********************************************************************************/
57
58 #End Region
59
60 Imports Microsoft.VisualBasic.ComponentModel.Collection.Generic
61 Imports Microsoft.VisualBasic.Language
62
63 Namespace CommandLine.Reflection
64
65     ''' <summary>
66     ''' A very basically type in the <see cref="CommandLine"/>
67     ''' </summary>
68     Public MustInherit Class CLIToken : Inherits Attribute
69         Implements IReadOnlyId
70
71         ''' <summary>
72         ''' Name of this token object, this can be parameter name or api name.
73         ''' </summary>
74         ''' <returns></returns>
75         Public Overridable ReadOnly Property Name As String Implements IReadOnlyId.Identity
76
77         ''' <summary>
78         ''' Init this token by using <see cref="name"/> value.
79         ''' </summary>
80         ''' <param name="name">Token name</param>
81         Sub New(name As String)
82             Me.Name = name
83         End Sub
84
85         Public Overrides Function ToString() As String
86             Return Name
87         End Function
88     End Class
89
90     ''' <summary>
91     ''' 可以将这个自定义属性添加到类型的属性上面,添加额外的命名以及类型之类的标记
92     ''' </summary>
93     <AttributeUsage(AttributeTargets.Property, AllowMultiple:=False, Inherited:=True)>
94     Public Class Argv : Inherits CLIToken
95
96         ''' <summary>
97         ''' 对于<see cref="CLITypes.String"/>和<see cref="CLITypes.File"/>
98         ''' 程序会有不同的处理操作,虽然二者的值都是字符串输入
99         ''' </summary>
100         ''' <returns></returns>
101         Public ReadOnly Property Type As CLITypes
102         ''' <summary>
103         ''' Optional commandline arguments.(本属性标记一个命令行字符串之中的可选参数)
104         ''' </summary>
105         ''' <returns></returns>
106         Public ReadOnly Property IsOptional As Boolean
107
108         ''' <summary>
109         ''' 默认为参数字符串通用类型
110         ''' </summary>
111         ''' <param name="name$"></param>
112         ''' <param name="type"></param>
113         ''' <param name="optional">
114         ''' Optional commandline arguments.(本属性标记一个命令行字符串之中的可选参数)
115         ''' </param>
116         Sub New(name$,
117                 Optional type As CLITypes = CLITypes.String,
118                 Optional [optional] As Boolean = False)
119
120             Call MyBase.New(name)
121
122             Me.Type = type
123             Me.IsOptional = [optional]
124         End Sub
125
126         Public Overrides Function ToString() As String
127             With $"Dim [{Name}] As {Type.ToString}"
128                 If IsOptional Then
129                     Return $"[{ .ByRef}]"
130                 Else
131                     Return .ByRef
132                 End If
133             End With
134         End Function
135     End Class
136
137     ''' <summary>
138     ''' 这个自定义属性添加在Class申明上表示该class类的命令行参数的名称都会添加这个prefix
139     ''' </summary>
140     <AttributeUsage(AttributeTargets.Class Or AttributeTargets.Property, AllowMultiple:=False, Inherited:=True)>
141     Public Class Prefix : Inherits Attribute
142
143         Public ReadOnly Property Value As String
144
145         Sub New(prefix As String)
146             Value = prefix
147         End Sub
148
149         Public Overrides Function ToString() As String
150             Return Value
151         End Function
152     End Class
153 End Namespace