I’m not sure of the syntax necessary to access a class’s attributes inside of a Dictionary declaration.
Public food As New Dictionary(Of String, cheese) From
{
{"cheese1", New cheese},
{"cheese2", New cheese},
{"cheese3", New cheese}
}
Public Class cheese
Public info As New Dictionary(Of String, Array) From
{
{"attributes1",
{New Dictionary(Of String, String) From
{
{"name", "test"},
{"taste", vbNullString},
{"color", vbNullString}
}
}
},
{"attributes2",
{New Dictionary(Of String, String) From
{
{"name", "test"},
{"taste", vbNullString},
{"color", vbNullString}
}
}
}
}
End Class
So if I want to test it and use MsgBox() how do I trickle down to pull, say, name in food > cheese1 > info > attributes2 > name?
EDIT:
I just realized that Array in info needs to be a Dictionary for an associative array, so please ignore that error and just assume it is a Dictionary for this question’s sake.
Well, here’s how to get there (taking your
Arraycomment into account):If you left that inner dictionary as
<String, Array>then you would have this, which would return the 0th dictionary’s “name” value:But as I hinted at in my comment, this is really poor design. Here would be one way to redo this:
This can be accomplished by refactoring your classes into this:
There are probably better ways yet, but it’s just here for illustration.