Re: Copy: Hashtable to Properties

Tech-Archive recommends: Speed Up your PC by fixing your registry



You'd have to use reflection, something like this:

Type objType;
PropertyInfo property;

objType = obj.GetType();

foreach( DictionaryEntry de in hash ) {
property = objType.GetProperty( de.key );
property.SetValue( obj, hash[ de.key ] );
}

You may have to cast the value out of the Hashtable to match what the
property expects, so you may need to have a switch statement in there
that looks at property.PropertyType.

HTH
Andy

.



Relevant Pages

  • Re: god im a noob
    ... The loop variable of a foreach is ... A DBM hash is stored on disk. ... Each invocation of this subroutine has its own %numbers_colors ...
    (comp.lang.perl.misc)
  • Re: Password scrambler program
    ... foreach { ... You also enter a purpose for the password (such ... Hash(Hash(M), PIN, Site, Purpose, 1) ...
    (sci.crypt)
  • Re: match an array element
    ... for each match recording an hash element like this one: ... Every file is a list of unique words, so I'm sure there will not be ... foreach $file ... You probably need either a Hash of Hashes: ...
    (perl.beginners)
  • Re: match an array element
    ... for each match recording an hash element like this one: ... > 1) is there a way to avoid a foreach in a foreach? ... $ARGV holds the name of the file currently being read. ... the ARGV filehandle must be closed at eof to reset the line counter $. ...
    (perl.beginners)
  • Archive::Zip and hash issues
    ... Firt I built a hash ... foreach my $log { ... Do You Yahoo!? ... Mail has the best spam protection around ...
    (perl.beginners)