Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

How to convert a string to lambda expression?

How to convert a string to lambda expression?

How to convert a string to lambda expression?

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close