Passing a condition into Func of a Tuple

I am trying to create a list of tuples with properties and conditions for their validation. So I had this idea in mind:

List<Tuple<string, string, Func<bool>>> properties = new List<Tuple<string, string, Func<bool>>> { Tuple.Create(FirstName, "User first name is required", ???), }; ...

How can I pass expression of type (FirstName == null) as Func ?

-------------Problems Reply------------

Like this (using a lambda expression):

List<Tuple<string, string, Func<bool>>> properties = new List<Tuple<string, string,
Func<bool>>>
{
Tuple.Create<string, string, Func<bool>>(
FirstName,
"User first name is required",
() => FirstName == null),
};

Something like this:

List<Tuple<string, string, Func<bool>>> properties = new List<Tuple<string, string, Func<bool>>>
{
Tuple.Create(FirstName, "User first name is required", new Func<bool>(() => FirstName == null)),
};

Note that there are some limitatons to type inference for lambda expressions... for this reason the new Func<bool> way of building a delegate is used.

Alternatives:

Tuple.Create(FirstName, "User first name is required", (Func<bool>)(() => FirstName == null)),
Tuple.Create<string, string, Func<bool>>(FirstName, "User first name is required", () => FirstName == null),
new Tuple<string, string, Func<bool>>(FirstName, "User first name is required", () => FirstName == null),

In the end you have to repeate the Func<bool> somewhere.

Category:c# Views:7 Time:2019-02-09

Related post

  • Parse boolean condition into expression tree 2011-02-01

    If I have a method that takes a boolean like: public void Foo(boolean condition) And call it like this: Foo("MyField" == "MyValue"); Can I compose that into an expression tree in order to construct a query to some other datasource that will use MyFie

  • jQuery $.ajax(), pass success data into separate function 2010-03-08

    I am using the jQuery $.ajax() function. I have put this into a parent function, which passes some values into the ajax function. What I would like to do, is have a user defined callback function, which gets the data param passed in from the ajax suc

  • how to pass an array into an function and in the function count how many numbers are in a range? 2010-04-24

    #include <iostream> #include <fstream> using namespace std; int calculate_total(int exam1[], int exam2[], int exam3[]); // function that calcualates grades to see how many 90,80,70,60 int exam1[100];// array that can hold 100 numbers for

  • How can I dynamically pass a condition and a method to a recursive method 2011-10-24

    I want to make a method like this, public dynamic Traverse(dynamic entity, conditions, method) { foreach (var propInfo in GetTraversableProperties(entity)) { if (condition) method(propInfo.GetValue(etc)); Traverse(propInfo, condition, method); } retu

  • Should the UI layer be able to pass lambda expressions into the service layer instead of calling a specific method? 2012-01-24

    The ASP.NET project I am working on has 3 layers; UI, BLL, and DAL. I wanted to know if it was acceptable for the UI to pass a lambda expression to the BLL, or if the UI should pass parameters and the Service method should use those parameters to con

  • How do I pass a parameter into an access report programatically? 2008-12-29

    I've got an existing Access MDB. I'm adding a command button to an existing Form that runs an existing report. The change being made is that this button needs to pass in a parameter containing the ID of the record being reported on - currently the re

  • In zsh, how do I pass anonymous arrays into functions? 2009-01-14

    In zsh, how do I pass anonymous arrays into functions? e.g. looking for something like: foo() { echo ${1[2]} '\n'; } a=(abc def ghi) foo $a --> def Or ideally: foo (abc def ghi) --------------Solutions------------- You can't. Functions take positi

  • Flash/AS3 passing a method into a method 2009-03-10

    I am trying to make a transitionmanager and I wish to pass a method into a method, because I would like to make a bunch of different seperate transition methods which I fetch as a public static function from a Transitions class. Example in Transition

  • how to pass int/char into system() a Linux system call 2009-03-31

    Ok it might sounds dumb, but I couldn't figure out a way to pass int/char into this system call here is how I would like it to work system ("cal %d %d", month, year); I expect this will give me the following command on terminal "cal 3 2009" and the t

  • how to pass the parameter into batch file? 2009-07-06

    how to pass the parameter into batch file using java runtime.exec(). **Process pp = run.exec("C:\Program Files\Apache Group\Tomcat 4.1\bin\RMIClientInvoker.bat C:\Program Files\Apache Group\Tomcat 4.1\bin localhost date");** when i using this coding

  • How can I convert a URL query string into a list of tuples using Python? 2009-08-19

    I am struggling to convert a url to a nested tuple. # Convert this string str = 'http://somesite.com/?foo=bar&key=val' # to a tuple like this: [(u'foo', u'bar'), (u'key', u'val')] I assume I need to be doing something like: url = 'http://somesite

  • What's the best way to pass complex data into an ASP.Net control? 2009-10-24

    I want to pass complex information into a control. The equivalent of an entire XML document. What would be the best way to accomplish something like this: <MyPrefix:MyControl runat="server"> <Actions> <Action Name="Value" SomeParam="So

  • How to pass a variable into regex in jQuery/Javascript 2009-11-08

    Is there a way to pass a variable into a regex in jQuery/Javascript? I wanna do something like: var variable_regex = "bar"; var some_string = "foobar"; some_string.match(/variable_regex/); In Ruby you would be able to do: some_string.match(/#{variabl

  • Does passing a struct into an interface field allocate? 2009-11-29

    I have a structure something like this struct MyStructure :IFoo { } and a method like this: public BarThisFoo(IFoo a) { } my question is does passing the structure into that method "box" the structure, thus causing a garbage allocation? Addendum: Bef

  • Convert nested Lists into a List of Tuples 2009-11-30

    I have the following list ["txtvers=1","userid=3A6524D4-E31C-491D-94DD-555883B1600A","name=Jarrod Roberson","version=2"] I want to create a Dict where the left side of the = is the key and the right side is the value. Preferably where the key is an a

  • Passing a char** into a function by reference 2009-12-28

    Season's greetings! I have a function that prints out the contents of a char** that is being used as an array to store a number of strings. The is declared like this: char** commandArray = (char**)malloc(historySize); where historySize is a global in

  • Codeigniter: Pass form variable into URI 2010-01-03

    Not sure if this can be done but it seems my main issue is because i have a default route to a method called "index." I want to be able to list all users tagged with a specific keyword. In addition, users can search for other users based on these key

  • Passing an array into hidden_field ROR 2010-01-06

    I'm trying to pass an array into a hidden_field. The following User has 3 roles [2,4,5] >> u = User.find_by_login("lesa") => #<User id: 5, login: "lesa", email: "[email protected]", crypted_password: "0f2776e68f1054a2678ad69a3b28e35a

  • Passing String parameter into Javascript 2010-01-23

    I am passing String parameter into javascript . But it is not being called. this is my script: function downloadPopup(testing){ alert(testing); } I am calling the javascript like this from my jsp page: <% String testing = "DSfsdsfd" ; %> <a

  • How to pass an array into a function, and return the results with an array 2010-01-28

    So I'm trying to learn how to pass arrays through a function, so that I can get around PHP's inability to return multiple values. Haven't been able to get anything to work so far, but here is my best try. Can anybody point out where I'm going wrong?

  • Can I pass a delegate into a constructor of an abstract class from a descendant's constructor? 2010-02-15

    I have an abstract class which requires a delegate to function. I pass the delegate into the constructor. Now that I have a non default constructor I need to call the abstract class's constructors from the concrete class which means that I need to us

  • Passing a 'var' into another method 2010-03-28

    I am probably totally missing the point here but.... How can I pass a 'var' into another method? (I am using linq to load XML into an Enumerable list of objects). I have differernt object types (with different fields), but the final step of my proces

  • Pass a variable into a trigger 2010-04-15

    I have a trigger which deals with some data for logging purposes like so: CREATE TRIGGER trgDataUpdated ON tblData FOR UPDATE AS BEGIN INSERT INTO tblLog ( ParentID, OldValue, NewValue, UserID ) SELECT deleted.ParentID, deleted.Value, inserted.Value,

  • How do I pass function parameters into a regex query? 2010-08-06

    How would I go about passing function parameters into a regex query? Many thanks. function match(str, arg1, arg2){ var result = str.match(/(arg1 | arg2)/m); log(result) //null } match('claire nick steve', 'nick','steve'); --------------Solutions-----

  • Passing table variable into dynamic SQL 2008 2010-08-10

    I need to run a dynamic sql which uses table variable created in the scope of the parent. How do I pass table variable into dynamic sql in SQL2008 ? --------------Solutions------------- Here's an end-end example: -- Define a custom TABLE type CREATE

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.074 (s). 11 q(s)