vb.net - VB .NET Access a class property by string value -


i have function updates client in database. client object passed in, along string array of fields/properties should updated. need way of accessing each property in client object, based on in array. basically, looking vb .net equivalent javascript:

var fields = ["firstname","lastname","dob"]; for(field in fields) {     var thisfield = fields[field];     client[thisfield] = obj[thisfield]; } 

any appreciated! stack.

you can use reflection this. without knowing more how data objects set up, can't give perfect example, here's general idea:

dim myperson new person myperson.firstname = "john" myperson.lastname  = "doe" myperson.dob       = #1/1/2000#  dim myupdates new dictionary(of string, object) myupdates.add("firstname", "adam") myupdates.add("lastname" , "maras") myupdates.add("dob"      , #1/1/1990#)  dim persontype type = gettype(person)  each kvp keyvaluepair(of string, object) in myupdates     dim propinfo propertyinfo = persontype.getproperty(kvp.key)      if propinfo isnot nothing         propinfo.setvalue(myperson, kvp.value)     end if next 

Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -