我有一个大型的分支,它们都有相同的超类和接口。
SuperClass:AbstractPackage 接口:IPackage
用这个做的类型。
Package0 .... Package723
我使用Activator.CreateInstance创建一个新的包实例,具体取决于模式,从UDP字节流中收到。
我在New Dictionary(Of UInt32,Type)中获得了所有已注册的包。
Uint32是包号(0-723),Type是任何Package0 - Package723类型。
问题是,Activator.CreateInstance会创建任何类型的类,我想知道我是否可以缩小范围?
我想让Dictionary(和Activator.CreateInstance)只接受包。 是可以的吗? 感谢
答案 0 :(得分:0)
这是我的新方法(我仍然需要再次添加所有类,但现在我至少知道它生成了什么类型。
Public Function getPackage(ByVal bytes() As Byte) As APackage
Dim pkgbytes As Byte() = New Byte(3) {}
Dim o As Integer = 0
For i As Integer = 8 To 11
pkgbytes(o) = bytes(i)
o += 1
Next
Dim package As APackage
Dim iT As UInt32 = UByteChunk.getUInt32(pkgbytes)
Select Case iT
Case 0
'0 Acknowledge
package = New Package0(bytes)
Case 152
'152 EventCall
package = New Package152(bytes)
Case 157, 162, 165, 166
' 157 Event Extension
' 162 Event Delta Call
' 165
' 166 Event Call Logging
package = New PackageCall(bytes)
Case 174
'174 Event Targeting
package = New Package174(bytes)
Case 187, 188
'187 SIP Rx
'188 SIP Tx
package = New PackageSIP(bytes)
Case 93, 501, 502, 626
'93 Version
'501 Info
'502 Info 2
'626 License
package = New PackageText(bytes)
Case 563
'563 System Endpoint
package = New Package563(bytes)
Case Else
package = New PackageDefault(bytes)
End Select
Return package
End Function