1 | #Region "Microsoft.VisualBasic::c55b84bc2b2bd1756ad3ad9baabbe692, Microsoft.VisualBasic.Core\ComponentModel\Settings\DataModels\BindMapping.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 BindMapping |
35 | ' |
36 | ' Properties: AsOutString, BindProperty, Description, Name, Type |
37 | ' Value |
38 | ' |
39 | ' Function: Initialize, IsFsysValid |
40 | ' |
41 | ' Sub: [Set] |
42 | ' |
43 | ' |
44 | ' /********************************************************************************/ |
45 | |
46 | #End Region |
47 | |
48 | Imports System.Reflection |
49 | |
50 | Namespace ComponentModel.Settings |
51 | |
52 | Public Class BindMapping : Inherits ProfileItem |
53 | Implements IProfileTable |
54 | |
55 | Dim _target As Object |
56 | |
57 | Public ReadOnly Property BindProperty As PropertyInfo |
58 | |
59 | Public Shared Function Initialize(attr As ProfileItem, prop As PropertyInfo, obj As Object) As BindMapping |
60 | Dim maps As New BindMapping With { |
61 | .Name = attr.Name, |
62 | .Description = attr.Description, |
63 | .Type = attr.Type, |
64 | ._bindProperty = prop, |
65 | ._target = obj |
66 | } |
67 | Return maps |
68 | End Function |
69 | |
70 | Public ReadOnly Property Value As String Implements IProfileTable.value |
71 | Get |
72 | Dim result As Object = |
73 | BindProperty.GetValue(_target, Nothing) |
74 | Return Scripting.ToString(result) |
75 | End Get |
76 | End Property |
77 | |
78 | Public Sub [Set](value As String) |
79 | Dim obj As Object = |
80 | Scripting.CTypeDynamic(value, _bindProperty.PropertyType) |
81 | Call _BindProperty.SetValue(_target, obj, Nothing) |
82 | End Sub |
83 | |
84 | ''' <summary> |
85 | ''' 打印在终端窗口上面的字符串 |
86 | ''' </summary> |
87 | ''' <returns></returns> |
88 | Public ReadOnly Property AsOutString As String |
89 | Get |
90 | Return String.Format("{0} = ""{1}""", Name, Value) |
91 | End Get |
92 | End Property |
93 | |
94 | Public Overrides Property Name As String Implements IProfileTable.Name |
95 | Get |
96 | Return MyBase.Name |
97 | End Get |
98 | Set(value As String) |
99 | MyBase.Name = value |
100 | End Set |
101 | End Property |
102 | |
103 | Public Overrides Property Type As ValueTypes Implements IProfileTable.Type |
104 | Get |
105 | Return MyBase.Type |
106 | End Get |
107 | Set(value As ValueTypes) |
108 | MyBase.Type = value |
109 | End Set |
110 | End Property |
111 | |
112 | Public Overrides Property Description As String Implements IProfileTable.Description |
113 | Get |
114 | Return MyBase.Description |
115 | End Get |
116 | Set(value As String) |
117 | MyBase.Description = value |
118 | End Set |
119 | End Property |
120 | |
121 | ''' <summary> |
122 | ''' 这个方法只是针对<see cref="ValueTypes.File"/>和<see cref="ValueTypes.Directory"/>这两种类型而言才有效的 |
123 | ''' 对于其他的类型数据,都是返回False |
124 | ''' </summary> |
125 | ''' <returns></returns> |
126 | Public Function IsFsysValid() As Boolean |
127 | If Type = ValueTypes.Directory Then |
128 | Return Value.DirectoryExists |
129 | ElseIf Type = ValueTypes.File Then |
130 | Return Value.FileExists |
131 | Else |
132 | Return False |
133 | End If |
134 | End Function |
135 | End Class |
136 | End Namespace |