|
I understand lambdas and the Func and Action delegates. But expressions stump me. In what circumstances would you use an Expression<Func<T>> rather than a plain old Func<T> ?
Started by Richard Nagle on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
For example, LINQ to SQL gets the expression and converts it to the equivalent SQL statement and submits it to server (rather than executing ... .
When you want to treat lambda expressions as expression trees and look inside them instead of executing them .
|
|
This seems inconsistent. Why do we use &Example::func instead of Example::func? is there a use for Example::func or &exampleFunction? it doesnt seem like we can make a reference to a function so that rules out Example::func. and i cant think of a way ...
Started by acidzombie24 on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
For a very rough example, suppose you have a class having several member variables by which you may need to sort of the elements of an array of that class type, like this:
struct CL { int x, y, z; }; bool sort_by... .
The point is using Function Pointers.
|
|
Hi there,
I've spent hours with this but haven't managed...
Please see example below - How can this be done?
The idea is to build a compiled expression of type Func<dynamic, dynamic> given an Expression<Func<T1,T2>> passed by the class...
Started by d. on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
Dynamic, dynamic> at this point given lambdaExpression? var func = lambdaExpression.Compile(); _compiledExpression = (dynamic x) => (dynamic)func((T1)x); } }
I was looking in to something similar.
|
Ask your Facebook Friends
|
Is there a faster way to cast Fun<TEntity, TId> to Func<TEntity, object>
public static class StaticAccessors<TEntity> { public static Func<TEntity, TId> TypedGetPropertyFn<TId>(PropertyInfo pi) { var mi = pi.GetGetMethod(...
Started by mythz on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
Notice that TResult is marked with "out" so its return value can be cast as a less-specific .
.NET 3.5 for Func .
In .NET 4.0 you can do this because the Func delegate marks TResult with the out modifier.
|
|
I have a method that currently takes a Func<Product, string> as a parameter, but I need it to be an Expression<Func<Product, string>> . Using AdventureWorks, here's an example of what I'd like to do using the Func.
private static void...
Started by Ecyrb on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
I would suggest building out the rest of your expression and then decompiling to see the generated ... .
You'll need to build your GroupBy expression by hand, which means you can't use anonymous type .
On second thought, compiling the expression won't work.
|
|
I have used C# expressions before based on lamdas, but I have no experience composing them by hand. Given an Expression<Func<SomeType, bool>> originalPredicate , I want to create an Expression<Func<OtherType, bool>> translatedPredicate...
Started by michielvoo on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
); // test with LINQ-to-Objects for simplicity var func = lambda.Compile(); bool withOdd = func(new Bar { Value = 7 }), withEven = func(new Bar { Value = 12 }); } }
Note however that this will be supported.
|
|
Quoting a code snippet :
/** * list_add - add a new entry * @new: new entry to be added * @head: list head to add it after * * Insert a new entry after the specified head. * This is good for implementing stacks. */ static inline void list_add(struct list...
Started by Tapioca on
, 9 posts
by 9 people.
Answer Snippets (Read the full thread at stackoverflow):
NOTE: If this is C++ then you might want to rethink calling your variables new , as... .
Eg, there may be a push() or an insert_head() or something like that .
However, there are probably other public entries that can share the code in __list_add() .
It can.
|
|
In the following code, both amp_swap() and star_swap() seems to be doing the same thing. So why will someone prefer to use one over the other? Which one is the preferred notation and why? Or is it just a matter of taste?
#include <iostream> using...
Started by vito on
, 10 posts
by 10 people.
Answer Snippets (Read the full thread at stackoverflow):
However, one is a reference (&) and the other is a pointer (*)
http://www.google.com/search?hl=en&q=pointers+vs+references&btnG=Google+Search&aq=1&oq=pointers+vs
I believe they both have their uses - as with... .
They are the exact same thing to the computer.
|
|
In the signature of a method I specify a Func, like so:
public void Method (Func<string, bool> func)
In LINQ, which method (from IEnumerable) will let me pass in a Func from the method parameter to the LINQ query? The other issue is, my func can...
Started by dotnetdev on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
The actual method implementation using LINQ would use Joel's aforementioned Where()
Edit: changed func constrained by the predicate passed....
Change your API's signature to be open:
public void Method<T> (Predicate<T> func)
Your.
|
|
Is there an equivilant in Python for PHPs call_user_func_array ?
Started by DerKlops on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
You could do:
getattr(obj, 'func')(*arr) # where obj is the namespace that hold func.
|