asp.net - Problems implementing a recursive find extension method -


i attempting implement recursive extension method in vb.net find objects property set can call so...

dim camp new campaignstructure 'populated full structure of course dim lstfounditems list(of categorystructure) = camp.categories.findrecursive((function(c) c.found = false), 3) 

my vb.net classess , modules this

imports system.runtime.compilerservices  namespace mystructure public class categorystructure     public property categoryid integer = nothing     public property name string     public property rank integer     public property found boolean = false     public property children new list(of categorystructure) end class  public class campaignstructure     public property campaignid string = nothing     public property categories list(of categorystructure) end class  public module controlextensions     <extension()> _     public function findrecursive(cs list(of categorystructure), predicate func(of categorystructure, boolean), depthlimit integer) list(of categorystructure)         if cs nothing orelse cs.count = 0             return new list(of categorystructure)()         end if          if depthlimit = 0             return cs.oftype(of categorystructure)().where(predicate).tolist()         else             '**error thrown here**             return cs.oftype(of categorystructure)().where(predicate).tolist().union(cs.cast(of categorystructure).select(of list(of categorystructure))(function(c) c.children.findrecursive(predicate, depthlimit - 1)).tolist())         end if     end function  end module  end namespace 

however i'm having casting problems when i'm unioning recursive result current list @ point in code marked. can see why that's happening, have no idea how resolve it. please not send me c# examples there no 'yield' alternative in vb.net

that's because both sides of union have different signatures.

cs.oftype(of categorystructure)().where(predicate).tolist() 

this returns list(of categorystructure).

cs.cast(of categorystructure).select(of list(of categorystructure))(function(c) c.children.findrecursive(predicate, depthlimit - 1)).tolist() 

this 1 returns list(of list(of categorystructure))

i think you're looking is:

return cs.oftype(of categorystructure)().where(predicate).union(cs.cast(of categorystructure).selectmany(function(c) c.children.findrecursive(predicate, depthlimit - 1))).tolist() 

selectmany returns flattened collection typed ienumerable(of categorystructure).


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -