-1 |
|
'Voorbeeld met fouten
Dim controlType As Type = FALFormBase
Dim senderType As Type = FALViewBase
If Not controlType Is Nothing And Not senderType Is Nothing Then
'controlType and senderType are not reconized
DirectCast(cntrl, controlType).FALUsernumber = DirectCast(sender, senderType).FALUsernumber
End If
'Voorbeeld dat werkt
If Not controlType Is Nothing And Not senderType Is Nothing Then
DirectCast(cntrl, FALFormBase).FALUsernumber = DirectCast(sender, FALViewBase).FALUsernumber
End If
'Voorbeeld met fouten Dim controlType As Type = FALFormBase Dim senderType As Type = FALViewBase If Not controlType Is Nothing And Not senderType Is Nothing Then 'controlType and senderType are not reconized DirectCast(cntrl, controlType).FALUsernumber = DirectCast(sender, senderType).FALUsernumber End If 'Voorbeeld dat werkt If Not controlType Is Nothing And Not senderType Is Nothing Then DirectCast(cntrl, FALFormBase).FALUsernumber = DirectCast(sender, FALViewBase).FALUsernumber End If
In het eerste voorbeeld krijg ik de fout bij controlType en senderType:
Type controlType is not defined.
Type senderType is not defined.
Het tweede voorbeeld werkt wel maar die types zouden in een controle aangepast moeten worden:
If cntrl.GetType.BaseType Is GetType(FALViewBase) Then
If sender.GetType.BaseType Is GetType(FALViewBase) Then
controlType = GetType(FALViewBase)
senderType = GetType(FALViewBase)
ElseIf sender.GetType.BaseType Is GetType(FALFormBase) Then
controlType = GetType(FALViewBase)
senderType = GetType(FALFormBase)
End If
ElseIf cntrl.GetType.BaseType Is GetType(FALFormBase) Then
If sender.GetType.BaseType Is GetType(FALViewBase) Then
controlType = GetType(FALFormBase)
senderType = GetType(FALViewBase)
ElseIf sender.GetType.BaseType Is GetType(FALFormBase) Then
controlType = GetType(FALFormBase)
senderType = GetType(FALFormBase)
End If
End If
If cntrl.GetType.BaseType Is GetType(FALViewBase) Then If sender.GetType.BaseType Is GetType(FALViewBase) Then controlType = GetType(FALViewBase) senderType = GetType(FALViewBase) ElseIf sender.GetType.BaseType Is GetType(FALFormBase) Then controlType = GetType(FALViewBase) senderType = GetType(FALFormBase) End If ElseIf cntrl.GetType.BaseType Is GetType(FALFormBase) Then If sender.GetType.BaseType Is GetType(FALViewBase) Then controlType = GetType(FALFormBase) senderType = GetType(FALViewBase) ElseIf sender.GetType.BaseType Is GetType(FALFormBase) Then controlType = GetType(FALFormBase) senderType = GetType(FALFormBase) End If End If
en op het einde dus de code in het begin van de post. Omdat ik die niet in elke if of elseif wil plaatsen (omdat me dat veel copy / paste werk kan besparen als er nog ooit andere properties doorgegeven zouden moeten worden)
Edit: Dit is blijkbaar een voorwaarde van CLR dat casting types bekend moeten zijn voor compiletime en dus iets wat ik niet zal kunnen implementeren.
|