1 #Region "Microsoft.VisualBasic::32440ddcf8c97f7be3cf918c5dd8093d, Microsoft.VisualBasic.Core\ApplicationServices\LanguageHelper\LanguageAttribute.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 LanguageAttribute
35     
36     '         Properties: Language, Text
37     
38     '         Constructor: (+1 OverloadsSub New
39     '         FunctionToString
40     
41     
42     ' /********************************************************************************/
43
44 #End Region
45
46 Namespace ApplicationServices.Globalization
47
48     <AttributeUsage(AttributeTargets.Property Or
49         AttributeTargets.Field Or
50         AttributeTargets.Enum, AllowMultiple:=True, Inherited:=True)>
51     Public Class LanguageAttribute : Inherits Attribute
52
53         Public ReadOnly Property Language As Integer
54         Public ReadOnly Property Text As String
55
56         ReadOnly _langEnum As Type
57
58         ''' <summary>
59         ''' 
60         ''' </summary>
61         ''' <param name="Language">The language of the target object.</param>
62         ''' <param name="Context"></param>
63         ''' <param name="langEnum">This type define should be a enum type.</param>
64         ''' <remarks></remarks>
65         Sub New(Language As Integer, Context As StringOptional langEnum As Type = Nothing)
66             Me.Language = Language
67             Me.Text = Context
68             Me._langEnum = langEnum
69         End Sub
70
71         Public Overrides Function ToString() As String
72             If _langEnum Is Nothing Then
73                 Return Text
74             Else
75                 Dim language As String = CTypeDynamic(Me.Language, _langEnum)
76                 Return $"@{language}  ""{Text}"""
77             End If
78         End Function
79
80         Public Shared Narrowing Operator CType(context As LanguageAttribute) As String
81             Return context.Text
82         End Operator
83     End Class
84 End Namespace