vb.net - Pass type as parameter to newtonsoft json deserialize -
i have working line of code
public shared function jsonarraytoobject(source string, result type) object return jsonconvert.deserializeobject(of pamanufacturer())(source) end function
result type , replace pamanufacturer gettype(result) or equivalent.
i haven't been able around problem. have hundred of these deserialize methods i'm sure should able use result variable somehow.
you can use generic functions (of deserializeobject
one) this:
public shared function jsonarraytoobject(of t)(source string) t() return jsonconvert.deserializeobject(of t())(source) end function
where call as:
dim arr pamanufacturer() = jsonarraytoobject(of pamanufacturer())(somesourcestring)
though if level, 1 wonders why use function @ all, , not have code call jsonconvert.deserializeobject
directly.
Comments
Post a Comment