Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to convert a string to lambda expression?

Status
Not open for further replies.

WomanPro

Programmer
Nov 1, 2012
180
GR
Hello anyone, I have big lambda expression with many lines in vb.net.
It runs perfectly for me and it returns a boolean

Code:
CoverLonely = FilteredFreeGts.Select(Function(b) New With {
                          .Position = b.Position,
                          .GtsInfo = GtsInfo_,
                          .ChckFrd = .GtsInfo.FrdIenum.AsEnumerable,
                          .FrdIenumOfIenum = GtsFltrdIenum.Select(Function(ChckN) New With
                          {.CrntFrd = ChckN.SelectMany(Function(elm) elm.FRd.Select(Function(elmk) elmk))}.
                          CrntFrd.Select(Function(CrntFrd) CrntFrd)),
                          .FrdElement = .GtsInfo.TargetPosition,
                          .RollInPositions = LonelyGtsInDngr.Select(Function(t) GtsInfo_.Rd.Select(Function(FrdS) FrdS = t.pos _
                          And FrdS > Dice And
                          b.Position.stack.Count = 1 And t.stack.Count = 1).Any(Function(r) r)),
                          .FreeSteps = b.FreeSteps}).
                          Where(Function(i) i.GtsInfo.FrdDblIenum.Select(Function(iss) iss.Select(Function(js) _
                          EmptyRdPoint2CrucialArea(js, Dice, True) = False _
                          And Backgammon.CheckFreePosPc(js)).Count = i.FreeSteps).Any And '	(i.ChckFrd.min >= QuartetLbound And i.ChckFrd.min <= QuartetUbound) And _
                          i.Position.pos = i.GtsInfo.FrdIenum.Max + Dice And
                          i.Position.stack.Count = 1 And i.Position.pos <> 0).Any

When I get true value I am getting the firstElement of this sequence with an if statement. So, instead of any at the end I use .FirstOrDefault.Position which runs perfectly too.
I thought instead of writing this big code two times because it is not very easy readable, to convert the lambda expression to string and execute it but I don't know how to do that.
It's very easy to make it a string and change the last peace from .any to .FirstOrDefault.Position or whatever I need, but lambda expressions are not strings. So, how can I do this conversion? Or is there any way of executing a lambda expression through a string and how? I searched on google but I didn't find anything about vb.net, I found for other programming languages but nothing can work for vb.net. Any help will be much appreciated. Thank you so much in advanced.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top