properties - Passing a property as argument like a delegate in VB.net -


i know it's possible pass function or sub using addressof pass delegate, in threadstart definition.

dim othstart new system.threading.thread.threadstart(addressof mysub) 

now have program in same processing on , over, on differents properties of same object. part of code have. show 2 iterations, there 9 in total , there other processing didn't include yet bigger.

if _oinforefbase.infostr1column = ""     _oinforefbase.infostr1column = ocolumn.columnname     getheader(colinfostr1, _oinfotable.nomtable, ocolumn.columnname)     _oinforefbase.infostr1numeric = boolisnumeric     _oinforefbase.infostr1float = boolisfloat     _oinforefbase.infodefaultstr1 = getdefault(colinfostr1, _oinfotable.nomtable, ocolumn.columnname)  elseif _oinforefbase.infostr2column = ""     _oinforefbase.infostr2column = ocolumn.columnname     getheader(colinfostr2, _oinfotable.nomtable, ocolumn.columnname)     _oinforefbase.infostr2numeric = boolisnumeric     _oinforefbase.infostr2float = boolisfloat     _oinforefbase.infodefaultstr2 = getdefault(colinfostr2, _oinfotable.nomtable, ocolumn.columnname) end if 

what define new function getotherinfo() call fill properties want, depend of iteration. like

getotherinfo(_oinforefbase.infostr1numeric,_oinforefbase.infostr1float,_oinforefbase.infostr1notnull,boolisnumeric,boolisfloat,colinfostr1,_oinfotable.nomtable, ocolumn.columnname) 

or

getotherinfo(_oinforefbase.infostr2numeric,_oinforefbase.infostr2float,_oinforefbase.infostr2notnull,boolisnumeric,boolisfloat,colinfostr2,_oinfotable.nomtable, ocolumn.columnname) 

and on. know syntax isn't right 1 send value of property, send can change it. properties validation in set if makes differences.

is possible? if how?

yes, it's possible. may want use system.reflection.propertyinfo has getvalue , setvalue methods get/set proeprty. , also, make life easier, may want wrap procedures property info easily.

pseudocode

function getpropertyinfo(of t class)(obj t, propertyfunc func(of t, object)) system.reflection.propertyinfo     ' implement using reflection or expression trees end function  ' sample usage:  sub test()     ' copy value obj1.name obj2.description     dim obj1 = new classa()     dim source = getpropertyinfo(obj1, function(t classa) t.name)      dim obj2 = new classb()     dim target = getpropertyinfo(obj2, function(t classb) t.description)      target.setvalue(obj2, source.getvalue) end sub 

and careful reflection: performance not good. work around this, try use expression trees build fast property wrappers - believe there plenty of resources on net that.

one example - http://geekswithblogs.net/madman/archive/2008/06/27/faster-reflection-using-expression-trees.aspx


Comments

Popular posts from this blog

php - get table cell data from and place a copy in another table -

javascript - Mootools wait with Fx.Morph start -

php - Navigate throught databse rows -