1 | Namespace ActiveBasic
|
---|
2 | Namespace Core
|
---|
3 |
|
---|
4 |
|
---|
5 | ' 中間的な実装(継承専用)
|
---|
6 | Class TypeBaseImpl
|
---|
7 | Inherits System.TypeInfo
|
---|
8 |
|
---|
9 | strNamespace As String
|
---|
10 | name As String
|
---|
11 | fullName As String
|
---|
12 |
|
---|
13 | ' メンバ情報
|
---|
14 | memberNames As *String ' 名前リスト
|
---|
15 | memberTypeFullNames As *String ' 型名リスト
|
---|
16 | memberCounts As Long ' 個数
|
---|
17 | memberInfosCache As System.Collections.Generic.List<System.Reflection.MemberInfo>
|
---|
18 |
|
---|
19 | Protected
|
---|
20 |
|
---|
21 | baseType As System.TypeInfo
|
---|
22 | 'interfaces As f(^^;;;
|
---|
23 |
|
---|
24 | Sub TypeBaseImpl( strNamespace As String, name As String, fullName As String )
|
---|
25 | This.strNamespace = strNamespace
|
---|
26 | This.name = name
|
---|
27 | This.fullName = fullName
|
---|
28 | This.baseType = Nothing
|
---|
29 | End Sub
|
---|
30 |
|
---|
31 | Sub ~TypeBaseImpl()
|
---|
32 | End Sub
|
---|
33 |
|
---|
34 | Public
|
---|
35 |
|
---|
36 | Sub SetMembers( memberNames As *String, memberTypeFullNames As *String, num As Long )
|
---|
37 | This.memberNames = memberNames
|
---|
38 | This.memberTypeFullNames = memberTypeFullNames
|
---|
39 | This.memberCounts = num
|
---|
40 |
|
---|
41 | /*
|
---|
42 | OutputDebugString( Ex"\r\n" )
|
---|
43 | Dim i As Long
|
---|
44 | For i=0 To ELM(num)
|
---|
45 | OutputDebugString( memberNames[i] )
|
---|
46 | OutputDebugString( ", " )
|
---|
47 | OutputDebugString( memberTypeFullNames[i] )
|
---|
48 | OutputDebugString( Ex"\r\n" )
|
---|
49 | Next
|
---|
50 | */
|
---|
51 | End Sub
|
---|
52 |
|
---|
53 |
|
---|
54 | '----------------------------------------------------------------
|
---|
55 | ' Public properties
|
---|
56 | '----------------------------------------------------------------
|
---|
57 |
|
---|
58 | Override Function BaseType() As System.TypeInfo
|
---|
59 | Return baseType
|
---|
60 | End Function
|
---|
61 |
|
---|
62 | Sub SetBaseType( baseType As System.TypeInfo )
|
---|
63 | This.baseType = baseType
|
---|
64 | End Sub
|
---|
65 |
|
---|
66 | Override Function FullName() As String
|
---|
67 | Return fullName
|
---|
68 | End Function
|
---|
69 |
|
---|
70 | Override Function IsArray() As Boolean
|
---|
71 | Return False
|
---|
72 | End Function
|
---|
73 |
|
---|
74 | Override Function IsByRef() As Boolean
|
---|
75 | Return False
|
---|
76 | End Function
|
---|
77 |
|
---|
78 | Override Function IsClass() As Boolean
|
---|
79 | Return False
|
---|
80 | End Function
|
---|
81 |
|
---|
82 | Override Function IsEnum() As Boolean
|
---|
83 | Return False
|
---|
84 | End Function
|
---|
85 |
|
---|
86 | Override Function IsInterface() As Boolean
|
---|
87 | Return False
|
---|
88 | End Function
|
---|
89 |
|
---|
90 | Override Function IsPointer() As Boolean
|
---|
91 | Return False
|
---|
92 | End Function
|
---|
93 |
|
---|
94 | Override Function IsValueType() As Boolean
|
---|
95 | Return False
|
---|
96 | End Function
|
---|
97 |
|
---|
98 | Override Function Name() As String
|
---|
99 | Return name
|
---|
100 | End Function
|
---|
101 |
|
---|
102 | Override Function Namespace() As String
|
---|
103 | Return strNamespace
|
---|
104 | End Function
|
---|
105 |
|
---|
106 |
|
---|
107 |
|
---|
108 | '----------------------------------------------------------------
|
---|
109 | ' Public methods
|
---|
110 | '----------------------------------------------------------------
|
---|
111 |
|
---|
112 | Override Function GetMembers() As System.Collections.Generic.List<System.Reflection.MemberInfo>
|
---|
113 | If Object.ReferenceEquals( memberInfosCache, Nothing ) Then
|
---|
114 | ' キャッシュにないときは生成する
|
---|
115 | memberInfosCache = New System.Collections.Generic.List
|
---|
116 | Dim i As Long
|
---|
117 | For i=0 To ELM(memberCounts)
|
---|
118 | memberInfosCache.Add( New System.Reflection.MemberInfo( memberNames[i], _System_TypeBase_Search( memberTypeFullNames[i] ) ) )
|
---|
119 | Next
|
---|
120 | End If
|
---|
121 |
|
---|
122 | Return memberInfosCache
|
---|
123 | End Function
|
---|
124 |
|
---|
125 | End Class
|
---|
126 |
|
---|
127 |
|
---|
128 | ' 値型を管理するためのクラス
|
---|
129 | Class _System_TypeForValueType
|
---|
130 | Inherits TypeBaseImpl
|
---|
131 | Public
|
---|
132 | Sub _System_TypeForValueType( name As String )
|
---|
133 | TypeBaseImpl( "", name, name )
|
---|
134 | End Sub
|
---|
135 |
|
---|
136 | Override Function IsValueType() As Boolean
|
---|
137 | Return True
|
---|
138 | End Function
|
---|
139 | End Class
|
---|
140 |
|
---|
141 | ' クラスを管理するためのクラス
|
---|
142 | Class _System_TypeForClass
|
---|
143 | Inherits TypeBaseImpl
|
---|
144 |
|
---|
145 | Public
|
---|
146 | referenceOffsets As *Long
|
---|
147 | numOfReference As Long
|
---|
148 |
|
---|
149 | Sub _System_TypeForClass( strNamespace As String, name As String, fullName As String, referenceOffsets As *Long, numOfReference As Long )
|
---|
150 | TypeBaseImpl( strNamespace, name, fullName )
|
---|
151 |
|
---|
152 | This.referenceOffsets = referenceOffsets
|
---|
153 | This.numOfReference = numOfReference
|
---|
154 | End Sub
|
---|
155 | Sub _System_TypeForClass( strNamespace As String, name As String, fullName As String )
|
---|
156 | TypeBaseImpl( strNamespace, name, fullName )
|
---|
157 | End Sub
|
---|
158 | Sub ~_System_TypeForClass()
|
---|
159 | End Sub
|
---|
160 |
|
---|
161 | Override Function IsClass() As Boolean
|
---|
162 | Return True
|
---|
163 | End Function
|
---|
164 | End Class
|
---|
165 |
|
---|
166 | ' インターフェイスを管理するためのクラス
|
---|
167 | Class _System_TypeForInterface
|
---|
168 | Inherits TypeBaseImpl
|
---|
169 | Public
|
---|
170 | End Class
|
---|
171 |
|
---|
172 | ' 列挙体を管理するためのクラス
|
---|
173 | Class _System_TypeForEnum
|
---|
174 | Inherits TypeBaseImpl
|
---|
175 | Public
|
---|
176 | End Class
|
---|
177 |
|
---|
178 | ' デリゲートを管理するためのクラス
|
---|
179 | Class _System_TypeForDelegate
|
---|
180 | Inherits TypeBaseImpl
|
---|
181 | Public
|
---|
182 | End Class
|
---|
183 |
|
---|
184 |
|
---|
185 | '--------------------------------------------------------------------
|
---|
186 | ' プロセスに存在するすべての型を管理する
|
---|
187 | '--------------------------------------------------------------------
|
---|
188 | Class _System_TypeBase
|
---|
189 | Static types As System.Collections.Generic.Dictionary<String, TypeBaseImpl>
|
---|
190 |
|
---|
191 | Static isReady = False
|
---|
192 |
|
---|
193 | Static Sub Add( typeInfo As TypeBaseImpl )
|
---|
194 | types.Add( typeInfo.FullName, typeInfo )
|
---|
195 | End Sub
|
---|
196 |
|
---|
197 | Static Sub InitializeValueType()
|
---|
198 | types = New System.Collections.Generic.Dictionary<String, TypeBaseImpl>(8191)
|
---|
199 |
|
---|
200 | ' 値型の追加
|
---|
201 | Add( _System_Static_New _System_TypeForValueType[ strNamespace = "", name = "Byte", fullName = "Byte" ] )
|
---|
202 | Add( _System_Static_New _System_TypeForValueType[ strNamespace = "", name = "SByte", fullName = "SByte" ] )
|
---|
203 | Add( _System_Static_New _System_TypeForValueType[ strNamespace = "", name = "Word", fullName = "Word" ] )
|
---|
204 | Add( _System_Static_New _System_TypeForValueType[ strNamespace = "", name = "Integer", fullName = "Integer" ] )
|
---|
205 | Add( _System_Static_New _System_TypeForValueType[ strNamespace = "", name = "DWord", fullName = "DWord" ] )
|
---|
206 | Add( _System_Static_New _System_TypeForValueType[ strNamespace = "", name = "Long", fullName = "Long" ] )
|
---|
207 | Add( _System_Static_New _System_TypeForValueType[ strNamespace = "", name = "QWord", fullName = "QWord" ] )
|
---|
208 | Add( _System_Static_New _System_TypeForValueType[ strNamespace = "", name = "Int64", fullName = "Int64" ] )
|
---|
209 | Add( _System_Static_New _System_TypeForValueType[ strNamespace = "", name = "Boolean", fullName = "Boolean" ] )
|
---|
210 | Add( _System_Static_New _System_TypeForValueType[ strNamespace = "", name = "Single", fullName = "Single" ] )
|
---|
211 | Add( _System_Static_New _System_TypeForValueType[ strNamespace = "", name = "Double", fullName = "Double" ] )
|
---|
212 | End Sub
|
---|
213 |
|
---|
214 | Static Sub InitializeUserTypes()
|
---|
215 | ' このメソッドの実装はコンパイラが自動生成する
|
---|
216 |
|
---|
217 | '例:
|
---|
218 | 'Add( New _System_TypeForClass( "System", "String", "System.String", [__offsets...], __numOfOffsets ) )
|
---|
219 | '...
|
---|
220 | End Sub
|
---|
221 | Static Sub InitializeUserTypesForBaseType()
|
---|
222 | ' このメソッドの実装はコンパイラが自動生成する
|
---|
223 |
|
---|
224 | '例:
|
---|
225 | 'Search( "System.String" ).SetBaseType( Search( "System.Object" ) )
|
---|
226 | '...
|
---|
227 | End Sub
|
---|
228 |
|
---|
229 | Public
|
---|
230 | Static Sub Initialize()
|
---|
231 | ' 値型を初期化
|
---|
232 | InitializeValueType()
|
---|
233 |
|
---|
234 | ' Class / Interface / Enum / Delegate を初期化
|
---|
235 | InitializeUserTypes()
|
---|
236 |
|
---|
237 | isReady = True
|
---|
238 |
|
---|
239 | ' 基底クラスを登録
|
---|
240 | InitializeUserTypesForBaseType()
|
---|
241 |
|
---|
242 | selfTypeInfo = _System_TypeBase.Search( "System.TypeInfo" ) As System.TypeInfo
|
---|
243 |
|
---|
244 | _System_DebugOnly_OutputDebugString( Ex"ready dynamic meta datas!\r\n" )
|
---|
245 | End Sub
|
---|
246 |
|
---|
247 | Static Sub _NextPointerForGC()
|
---|
248 | ' TODO: 実装
|
---|
249 | End Sub
|
---|
250 |
|
---|
251 | Static Function Search( fullName As String ) As TypeBaseImpl
|
---|
252 | If Object.ReferenceEquals(types, Nothing) Then
|
---|
253 | Return Nothing
|
---|
254 | End If
|
---|
255 |
|
---|
256 | If isReady = False Then
|
---|
257 | Return Nothing
|
---|
258 | End If
|
---|
259 |
|
---|
260 | Search = types.Item(fullName)
|
---|
261 |
|
---|
262 | If Object.ReferenceEquals( Search, Nothing ) Then
|
---|
263 | OutputDebugString("TypeSearch Failed: ")
|
---|
264 | If Not ActiveBasic.IsNothing(fullName) Then
|
---|
265 | OutputDebugStringW(StrPtr(fullName) As PWSTR)
|
---|
266 | OutputDebugString(Ex"\r\n")
|
---|
267 | OutputDebugStringA(StrPtr(fullName) As PSTR)
|
---|
268 | End If
|
---|
269 | OutputDebugString(Ex"\r\n")
|
---|
270 | End If
|
---|
271 | End Function
|
---|
272 |
|
---|
273 | Static Function IsReady() As Boolean
|
---|
274 | Return isReady
|
---|
275 | End Function
|
---|
276 |
|
---|
277 | Static selfTypeInfo As System.TypeInfo
|
---|
278 |
|
---|
279 | End Class
|
---|
280 |
|
---|
281 |
|
---|
282 | End Namespace
|
---|
283 | End Namespace
|
---|
284 |
|
---|
285 | Function _System_TypeBase_Search( fullName As String ) As ActiveBasic.Core.TypeBaseImpl
|
---|
286 | Return ActiveBasic.Core._System_TypeBase.Search( fullName )
|
---|
287 | End Function
|
---|