|
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.
|
|
Going from a lambda to an Expression is easy using a method call...
public void GimmeExpression(Expression<Func<T>> expression) { ((MemberExpression)expression.Body).Member.Name; // "DoStuff" } public void SomewhereElse() { GimmeExpression...
Started by Dave Cameron on
, 6 posts
by 6 people.
Answer Snippets (Read the full thread at stackoverflow):
If there's any way you could do so (due to optimizations and other things done by the compiler, some data might be thrown away, so it might be impossible to ... .
Func<T> represents a generic delegate and not an expression.
Ooh, it's not easy at all.
|
|
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.
|
|
I ran across an interesting issue today. We have an application that utilizes Zend Frameworks caching functionality. A request to this application typically calls a factory method using the following line
$result = call_user_func_array(array("myclass"...
Started by goose77 on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
$dummy = new MyClassName; call_user_func_array(array('MyClassName', 'method.
Which version of php are you using? There was an issue in combining call_user_func_array solves it for you.
|
|
My problem:
I have a wealth of atom RSS feed files which have many different atom entries in them and a few overlapping entries between files. I need to find and return an entry based on a URL from any one of the RSS feeds.
Technologies:
This code is ...
Started by teastburn on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
The first element:
<func:function name="cozi:findPost"> <xsl:param name="post-url"/> <-of select="$feed-entry"/> </xsl:if> </xsl:for-each> </xsl:variable> <func:result select="$feedList[1]"/> <....
|
|
When a C function does not accept any arguments, does it have to be declared/defined with a "void" parameter by the language rules? PC-Lint seems to have problems when there's nothing at all in the argument-list, and I was wondering if it's something ...
Started by noamtm on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
According to Wikipedia here, the declaration func() does basically declare the function.
IIRC func(void) in C will declare a function that takes no parameters whereas func() declares-ANSI C.
|