That's an interesting question (to which I don't have an immediate answer).
My first line of attack would be the serializer routines: presumably the first bytes from those would indicate what the type is.
Another approach is: cast the thing to an Object, and then inside your routine, have a cascade of something like:
Sub DoSomething (subElement as Object, Action As String)
If subElement Is Button Then
Dim B as Button = Object 'cast object to its type
B.Text = Action 'eg
Else If subElement Is Label Then
Dim L as Label = Object
L.Text = Action
Else If subElement Is Webview then
Dim W as Webview = Object
W.Request = Action & " " & URL '???
Else
log("Unrecognized object type")
End if
End Sub
I haven't actually run that code, but I'm sure it'll work third try