Form Tag GetType

S-Soft 646 Reputation points
2022-10-03T20:55:58.877+00:00

Hello,
Going to call a form as Modal from different places.

Dim F As New BlahForm
F.Tag = blah1or2
F.ShowDialog

I might pass a X509Certificate2 or a X509Certificate2Collection to the tag, different types!
On the target form, how to detect the data type?

Me.Tag.GetType.ToString will resolve:
System.Security.Cryptography.X509Certificates.X509Certificate2
or
System.Security.Cryptography.X509Certificates.X509Certificate2Collection

But is there a non string way to get the real data type?

And generally is it a good approach?
Thanks.

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,608 questions
{count} votes

Accepted answer
  1. LesHay 7,126 Reputation points
    2022-10-03T21:21:28.27+00:00

    Hi
    What I would do faced with that is to build a Select statement for all the known types that may be passed (assuming you do not plan on using dozens of types).

    Select Me.Tag.GetType  
    Case GetType(System.Security.Cryptography.X509Certificates.X509Certificate2)  
    ' ...........  
      
    Case GetType(System.Security.Cryptography.X509Certificates.X509Certificate2Collection)  
    ' ...........  
      
    End Select  
    
    0 comments No comments

0 additional answers

Sort by: Most helpful