| 1 |
#Region "Microsoft.VisualBasic::a7c4b491a00c4c994d27672e7b0d7b05, Microsoft.VisualBasic.Core\ComponentModel\DataSource\Property\Controls.vb"
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
#End Region
|
| 49 |
|
| 50 |
Imports System.Dynamic
|
| 51 |
Imports System.Runtime.CompilerServices
|
| 52 |
Imports System.Text
|
| 53 |
Imports System.Web.Script.Serialization
|
| 54 |
Imports System.Xml.Serialization
|
| 55 |
|
| 56 |
Namespace ComponentModel.DataSourceModel
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
Public Module ControlsExtension
|
| 64 |
|
| 65 |
<Extension> Public Function GetMoreProps(ByRef ctrl As Control) As ExtendedProps
|
| 66 |
If Not ctrl.Tag Is Nothing Then
|
| 67 |
Dim tagType As Type = ctrl.Tag.GetType
|
| 68 |
|
| 69 |
If tagType.Equals(GetType(ExtendedProps)) OrElse tagType.IsInheritsFrom(GetType(ExtendedProps)) Then
|
| 70 |
Return DirectCast(ctrl.Tag, ExtendedProps)
|
| 71 |
Else
|
| 72 |
Return Nothing
|
| 73 |
End If
|
| 74 |
Else
|
| 75 |
Dim tag As New ExtendedProps
|
| 76 |
ctrl.Tag = tag
|
| 77 |
Return tag
|
| 78 |
End If
|
| 79 |
End Function
|
| 80 |
|
| 81 |
<Extension> Public Function SetMoreProps(ByRef ctrl As Control, extraProps As ExtendedProps, Optional [overrides] As Boolean = False) As Boolean
|
| 82 |
If Not ctrl.Tag Is Nothing AndAlso Not [overrides] Then
|
| 83 |
Call VBDebugger.Warning("The control already has a tag data, and not allowed to overrides....")
|
| 84 |
Return False
|
| 85 |
Else
|
| 86 |
ctrl.Tag = extraProps
|
| 87 |
Return True
|
| 88 |
End If
|
| 89 |
End Function
|
| 90 |
End Module
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
Public Class ExtendedProps : Inherits Dynamic.DynamicObject
|
| 96 |
|
| 97 |
Dim __hash As [Property](Of Object)
|
| 98 |
|
| 99 |
<DataIgnored, XmlIgnore, ScriptIgnore>
|
| 100 |
Public Property DynamicHashTable As [Property](Of Object)
|
| 101 |
Get
|
| 102 |
If __hash Is Nothing Then
|
| 103 |
__hash = New [Property](Of Object)
|
| 104 |
End If
|
| 105 |
Return __hash
|
| 106 |
End Get
|
| 107 |
Set(value As [Property](Of Object))
|
| 108 |
__hash = value
|
| 109 |
End Set
|
| 110 |
End Property
|
| 111 |
|
| 112 |
Sub New()
|
| 113 |
End Sub
|
| 114 |
|
| 115 |
Sub New(init As [Property](Of Object))
|
| 116 |
__hash = init
|
| 117 |
End Sub
|
| 118 |
|
| 119 |
Public Overrides Function GetDynamicMemberNames() As IEnumerable(Of String)
|
| 120 |
Return DynamicHashTable.Properties.Keys
|
| 121 |
End Function
|
| 122 |
|
| 123 |
Dim __nameCache As StringBuilder = New StringBuilder
|
| 124 |
|
| 125 |
Public Overrides Function TryGetMember(binder As GetMemberBinder, ByRef result As Object) As Boolean
|
| 126 |
Dim name As String = binder.Name
|
| 127 |
|
| 128 |
If __nameCache.Length > 0 Then
|
| 129 |
Call __nameCache.Append("." & name)
|
| 130 |
name = __nameCache.ToString
|
| 131 |
End If
|
| 132 |
|
| 133 |
If DynamicHashTable.Properties.ContainsKey(name) Then
|
| 134 |
Call __nameCache.Clear()
|
| 135 |
Return DynamicHashTable.Properties.TryGetValue(name, result)
|
| 136 |
Else
|
| 137 |
result = Me
|
| 138 |
Return True
|
| 139 |
End If
|
| 140 |
End Function
|
| 141 |
|
| 142 |
Public Overrides Function TrySetMember(binder As SetMemberBinder, value As Object) As Boolean
|
| 143 |
Dim name As String = binder.Name
|
| 144 |
|
| 145 |
If __nameCache.Length > 0 Then
|
| 146 |
Call __nameCache.Append("." & name)
|
| 147 |
name = __nameCache.ToString
|
| 148 |
End If
|
| 149 |
|
| 150 |
If DynamicHashTable.Properties.ContainsKey(name) Then
|
| 151 |
__nameCache.Clear()
|
| 152 |
DynamicHashTable.Properties(name) = value
|
| 153 |
Else
|
| 154 |
|
| 155 |
End If
|
| 156 |
|
| 157 |
Return True
|
| 158 |
End Function
|
| 159 |
End Class
|
| 160 |
End Namespace
|