tagged [func]

Is Func<in T, out TResult> appropriate to use as a ctor arg when applying Dependency Injection?

Is Func appropriate to use as a ctor arg when applying Dependency Injection? Example: ``` public class BusinessTransactionFactory where T : IBusinessTransaction { readonly Func _createTransaction; ...

Why Func<T,bool> instead of Predicate<T>?

Why Func instead of Predicate? This is just a curiosity question I was wondering if anyone had a good answer to: In the .NET Framework Class Library we have for example these two methods: ``` public s...

18 Apr at 13:49

Extension method that extends T - bad practice?

Extension method that extends T - bad practice? I've read that it is usually bad practice to extend System.Object, which I do agree with. I am curious, however, if the following would be considered a ...

Why is Action/Func better than a regular Method in .Net?

Why is Action/Func better than a regular Method in .Net? I much prefer using an Action or a Func if I need a quick reusable piece of code, however others on my team don't like them or understand them....

9 Dec at 17:56

The request message was already sent. Cannot send the same request message multiple times

The request message was already sent. Cannot send the same request message multiple times Is there anything wrong with my code here? I keep getting this error: > System.InvalidOperationException: The ...

use Func<> (or Action<>) or create own delegate?

use Func (or Action) or create own delegate? Which one is better in, say, parameter type in a method (not related to LINQ). Apparently Func is better since it's simpler, more descriptive, and if every...

16 Dec at 08:5

Convert Func<T, String> to Func<T, bool>

Convert Func to Func I think my mind is exploding trying to figure out Funcs... If this makes no sense, I apologize, right now it make sense to me but its been a long day already .... 1) Assuming you ...

21 Aug at 12:13

How do I declare a Func Delegate which returns a Func Delegate of the same type?

How do I declare a Func Delegate which returns a Func Delegate of the same type? I'd like to write a method which does some work and finally returns another method with the same signature as the origi...

16 Jan at 17:17

converting a .net Func<T> to a .net Expression<Func<T>>

converting a .net Func to a .net Expression> Going from a lambda to an Expression is easy using a method call... But I would like to turn the Func in to an expression, o

8 Nov at 21:11

Lambda\Anonymous Function as a parameter

Lambda\Anonymous Function as a parameter I'm a very new to C#. Just playing around with it. Not for a real purpose. Is it possible to use a REAL anonymous funct

9 Sep at 01:29

Can someone explain what the C# "Func<T,T>" does?

Can someone explain what the C# "Func" does? I'm reading the Pro MVC 2 book, and there is an example of creating an extension method for the HtmlHelper class. Here the code example: And here is an exa...

15 Mar at 17:27

Using FluentValidation's WithMessage method with a list of named parameters

Using FluentValidation's WithMessage method with a list of named parameters I am using FluentValidation and I want to format a message with some of the object's properties value. The problem is I have...

5 Jan at 00:40

How can I pass in a func with a generic type parameter?

How can I pass in a func with a generic type parameter? I like to send a generic type converter function to a method but I can't figure out how to do it. Here's invalid syntax that explains what I lik...

24 Mar at 12:42

Assigning a Func to an Expression and vice versa

Assigning a Func to an Expression and vice versa I was tampering with Expressions and I got confused at some points 1. We can assign same LamdaExpression to both Expression and/or Func. But we cannot ...

5 Jan at 19:32

Encapsulating Action<T> and Func<T>?

Encapsulating Action and Func? I'm trying to make a design for some sort of IExecutable interface. I will not get into details, but the point is that I have several Actions that need to be executed fr...

25 Nov at 17:15

How do you use Func<> and Action<> when designing applications?

How do you use Func and Action when designing applications? All the examples I can find about Func and Action are as in the one below where you see they technically work but I would like to see them u...

How to invoke Expression<Func<Entity, bool>> against a collection

How to invoke Expression> against a collection I have an interface that defines a repository from the Repository pattern: I've implemented it against Entity Framework: ``` class EntityFrameworkReposit...

24 Sep at 03:51

Using LINQ's Zip with a closure that doesn't return a value

Using LINQ's Zip with a closure that doesn't return a value Disclaimer: this question is driven by my personal curiosity more than an actual need to accomplish something. So my example is going to be ...

19 Feb at 07:55

C#: Elegant way to wrap method calls

C#: Elegant way to wrap method calls Apologies for the fairly ambiguous title but what I'm trying to achieve is probably better stated in code. I have a WCF client. When I'm calling methods I would li...

11 Apr at 10:22

Why is Func<> created from Expression<Func<>> slower than Func<> declared directly?

Why is Func created from Expression> slower than Func declared directly? Why is a `Func` created from an `Expression>` via .Compile() considerably slower than just using a `Func` declared directly ? I...

A List<> of Func<>s, compile error with generic return type, but why?

A List of Funcs, compile error with generic return type, but why? This is a bit of a lengthy question, so please bear with me. I need to create a mapping between a set of strings and corresponding gen...

11 May at 15:34

Utilizing Funcs within expressions?

Utilizing Funcs within expressions? ## Background I have an example of a test that passes but an error that happens down the pipeline and I'm not sure why. I'd like to figure out what's going on but I...