vb.net - Make VB code that replaces LINQ expressions -


i found code on answered question c# - how xml deserialize object itself? code , want use in application target .net 2.0 compact framework, cant use linq expressions. there can tell me how can convert "normal vb" code?

original code from user wheelibin.

i went approach:

public class serialisableclass      public sub savetoxml(byval outputfilename string)         dim xmls = new system.xml.serialization.xmlserializer(me.gettype)         using sw = new io.streamwriter(outputfilename)             xmls.serialize(sw, me)         end using     end sub      private tempstate object = me     public sub readfromxml(byval inputfilename string)         dim xmls = new system.xml.serialization.xmlserializer(me.gettype)          using sr new io.streamreader(inputfilename)             tempstate = xmls.deserialize(sr)         end using          each pi in tempstate.gettype.getproperties()             dim name = pi.name              '  part cant figure out (how without linq)             dim realprop = (from p in me.gettype.getproperties                             p.name = name , p.membertype = reflection.membertypes.property).take(1)(0)             '  -------------------------------------------------------------             realprop.setvalue(me, pi.getvalue(tempstate, nothing), nothing)         next     end sub end class 

you can replace linq part "normal" for each loop, example :

dim realprop propertyinfo each p propertyinfo in me.gettype.getproperties()     if p.name = name , p.membertype = reflection.membertypes.property     'set `realprop` first `p` fulfil above `if` criteria'     'this equivalent linq (...).take(1)(0) does'         realprop = p         exit     end if next 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -