Manfred Singer
Manfred Singer

Reputation: 181

Looping through properties of a class

I use the following loop for looping through the properties of my class:

For Each prop As PropertyInfo In gData.GetType.GetProperties
                ...do something
Next

This are my properties in the class:

Public Property ID As String
    Public Property CC As Integer
    Public Property REP As New Dictionary(Of String, Dictionary(Of String, String))
    Public Property DAT As New Dictionary(Of String, Int16())
    Public Property MIB As New Dictionary(Of String, ArrayList)
    Public Property PDF As Byte()

I will ignore the property "CC", but I want to find out the content of the properties REP, DAT and MIB. The property PDF I only check for content.

My problem is, that I have no idea how to access e.g. REP.

REP is, as you can see, a dictionary. The content of the dict can be the following:

  1. only the string "HH"
  2. only the string "Rel"
  3. both strings

Depending on the content of the different properties I build a checksum.

How can I get the keys of the properties, so how can I check if the key "HH" of the property REP exists?

Upvotes: 0

Views: 255

Answers (1)

Chillzy
Chillzy

Reputation: 468

if gData.REP.ContainsKey("HH") then 
   'Blah blah
End If

Upvotes: 1

Related Questions