jeudi 18 février 2021

Iterate through a class and get value from a KeyValuePair list with the propertyname

Hi what is the best way to iterate through a class and get an ID from a KeyValuePair list with the property name?

I have a class:

bar {
 foo1 {}
 foo2 {}
 foo3 {
   prop1 {
     name : foobar1,
     amount : 2
   },
   prop2 {
     name : foobar2,
     amount : 3
   },
   ...
 }
 foo4 {}
}

And I have a List<KeyValuePair<string, string>>() which contains:

  prob1, 12345
  prob2, 44939
  ....

No I should iterate through the bar class and foreach property (foo1, foo2, foo3) I should get the value in the this KeyValuePar with the key which is in that case prop1 or prop2.

So the result should be in the end like :

{
  id : 12345 // this is from prop1
  name : foobar1
  amount : 2
},
{
  id : 44939 // this is from prop2
  name : foobar2
  amount : 3
}
...

Is there a smart way to do it?

Thanks in advance...





Aucun commentaire:

Enregistrer un commentaire