How to determine if an object is an assembly or a dictionary?

I have a nested tree of nodes that are either Dictionaries or Collections (I have no control over this structure - this is given to me). How to separate Dictionary nodes from Collections ?

I observe that the IsArray() function exists, but not IsCollection or IsDict()

+4
source share
2 answers
 Sub TestingType() Dim col As New Collection Dim dic As New Scripting.Dictionary Debug.Print TypeName(col) 'Collection Debug.Print TypeName(dic) 'Dictionary End Sub 
+6
source

Try something like this:

 If TypeOf YourObjectVariable Is Dictionary Then ' ... ElseIf TypeOf YourObjectVariable Is Collection Then ' ... Else ' Handle empty/other types here. End If 

You can use something like this to control the flow of execution in your code or to create your own IsCollection () and IsDictionary () functions.

+3
source

Source: https://habr.com/ru/post/1493069/


All Articles