func

Can you get a Func<T> (or similar) from a MethodInfo object?

UPDATE: The suggestion to use an expression tree to construct a lambda using the given MethodInfo, in conjunction with the Expression<TDelegate>.Compile method, proved to be a gold mine in my scenario. In the specific case where I was toying with this idea, I saw average execution time for a particular method go from ~0.25 ms to ~0.001 m...

Predicates and OrderBy , Func....

i understand that predicates are delegate to function which return bool and take generic param , i understand that when i say mycustomer => mycustomer.fullname == 1 it actually means: delegate (Customer mycustomer) { return mycustomer.fullName == "John"; } the paramter im passing in when i ...

Using Generic with Func as a parameter

My code is simply: public override C Calculator<C>(Team[] teams, Func<Team, C> calculatorFunc) { return teams.Average(calculatorFunc); } I get this error: Error 2 The type arguments for method 'System.Linq.Enumerable.Average(System.Collections.Generic.IEnumerable, System.Func)' cannot be inferred from the u...

i cant call my multidimensional array function from my main function. what is wrong with my parameters? declarations? variables? etc.

#include<stdio.h> #include<string.h> #define MAX_VAL 100 //Function declaration int input_values(int Z[][k], int j, int k); int main(void) { int A(int [ ][k], int, int); int m, n; char comm[100]; while(1){ printf("\n>>"); gets(comm); if(strcmp(comm,"MAKE A")== 0) input_values(A, j, k ); } } //make or overwri...

How to invoke Func to set a local List<>

I guess I am missing something here but can someone explain how I can get this to work I have a method that takes a Func, I want to execute that func in the method a store the result in a local var. internal List<MembershipUser> Users; internal void FindType<T>(Func<List<MembershipUser>, T> finder)where T : List<MembershipUser> { ...

C# Action and Func parameter overloads

I need a method that takes an Action (or a Func), but the Action has a mixed number of parameters. What is the most straight forward and compact way to implement these overloads: public void Execute<T>(Action<T> action, T param) { // TODO: Implement something like: // Execute(action, param, null); } public void Execute<T1,T2>(A...

Func for 5 arguments

I am working with System.Func but have reached a stumbling block with it. System.Func<TReturn> // (no arg, with return value) System.Func<T, TReturn> // (1 arg, with return value) System.Func<T1, T2, TReturn> // (2 arg, with return value) System.Func<T1, T2, T3, TReturn> // (3 arg, with return value) System.Func<T1, T2, T3, T4, TReturn>...

Get expression parameter name

I need to get the name of a expression parameter. What i want to do is similar to what FluentNhibernate does with column mapping: Map(x => x.Name) From this, i need "Name". How do I do this? I can get x by doing this: Expression<Func<User, object>> exp = x => x.Id; exp.Parameters[0].Name; But im not able to get "Name". Note th...

"The type already contains a definition for" with a Func and a Method

I have the following piece of code public static Func<PurchasingDataContext, int, int, List<Requisition>> GetRequisitions = CompiledQuery.Compile((PurchasingDataContext context, int userid, int requisitionState) => context.Requisitions.Where(r => r.UserId == userid && r.RequisitionId == requisitionState).ToList()); publ...

How can I create this Func?

Hi There... Inspired by: NServiceBus.Configure.With().Log4Net(a => a.YourProperty = "value"); I want to use something similar as configuration, suggestions are welcome. My biggest problem is that I can't quite figure out how to use the parameter input... What exactly is going on here? NServiceBus uses Log4Net, as instance? set wi...

Method to return a generic type when passing in a delegate as a parameter

I'm trying to 'genericize' some code we have spattered around our system. I want to: return a generic type, pass in some kind of delegate containing the method to be called. I'm pretty new to generics so any help appreciated. Below is where my finger in the air is(!) public static T ReturnSingleObject<T>(Func<string, int, T> dynam...

Can I define a method to accept EITHER a Func<T> OR an Expression<Func<T>>?

If I attempt to write two overloads of a method, one accepting an Expression<Func<T>> parameter and another accepting a Func<T>, I will get a compiler error on trying to call the method with a lambda expression because the two signatures create ambiguity. The following would be problematic, for example: Method(() => "Hello"); // Is that...

Running Into a Snag With Func

Hello All, I have a treeview that represents different filter items to a set of records. At runtime, I am setting each node's tag to a Func type. For example: myTreeView.Nodes.Add(New TreeNode("Node1")); myTreeView.Nodes["Node1"].Tag = New Func<MyRecordType, bool>(p=> p.Title == "test 1"); myTreeView.Nodes.Add(New TreeNode("Node2")); ...