Wednesday, 15 May 2013

vb.net - Passing object field ByRef causes it to be set, even if it's not changed -



vb.net - Passing object field ByRef causes it to be set, even if it's not changed -

working 3rd party api in .net. api doesn't handle dbnull well, have created little helper function called "setstringvalue" looks this:

public sub setstringfield(byref _destinationfield object, byval _value object) if not typeof _value dbnull _destinationfield = _value end if end sub

in main code, have line this:

setstringfield(someapiobject.fields(some_field_enum), datarow.item("sourcevalue"))

if follow flow of code when hits dbnull, never runs line:

_destinationfield = _value

yet, "someapiobject" reports field set , dirty, though never did. it's .net setting passed argument original value, because passed reference.

is expected? way avoid that?

could apiobject.fields(...) phone call what's turning object dirty, dirty, dirty, dirty, filthy, dirty, object?

rewrite function:

public sub setstringfield(o Øbject, e enüm, v Øbject) if not typeof v dbnull o.fields(e) = v end if end sub

then phone call like:

setstringfield(someapiobject, some_field_enum, datarow.item("sourcevalue"))

or crap. more umlauts.

vb.net

No comments:

Post a Comment