The following line works as expected, but I am a little concerned why:
getLine >>= \x-> getLine >>= \y-> return [x, y]
Consider the addition of parenthesis to scope the lambda expressions:
getLine >>= (\x-> getLine) >>= (\y-> return [x, y])
The second line is errorneous because x is not in scope when used in the return, and I am ha...
This may be familiar to some. I have a wrapper class Ex that wraps an expression tree with a bunch of implicit conversions and operators. Here is simplified version
public class Ex
{
Expression expr;
public Ex(Expression expr)
{
this.expr = expr;
}
public static implicit operator Expression(Ex rhs) { return...
I'm writing a function that will be passed a lambda expression, and I want to convert the parameters that the lambda takes to an object array.
The only way I've been able to do it is with code I borrowed from here, and my function looks something like this:
public class MyClassBase<T> where T : class
{
protected void DoStuff(Expre...
When I need the Expression Trees ?
And please provide us with a real world sample if available
Thanks in advance
...
Given either of the variables below, how can I 'inspect' them to obtain the parameter value passed in? i.e. 12345.
System.Func<DateTime> f1 = () => DateTime.Now.AddDays(12345);
System.Linq.Expressions.Expression<System.Func<DateTime>>
f2 = () => DateTime.Now.AddDays(12345);
Edit:
The two answers below by Mika...
Suppose I have a function which takes some form of predicate:
void Foo( boost::function<bool(int,int,int)> predicate );
If I want to call it with a predicate that always returns true, I can define a helper function:
bool AlwaysTrue( int, int, int ) { return true; }
...
Foo( boost::bind( AlwaysTrue ) );
But is there anyway to call t...
Has anyone had problems gettting associations to load using LINQ to SQL when your child record was loaded via a lambda query? For example:
var orderLine = db.OrderLines.
Where(ol => ol.ID == orderLineID select ol).
First();
// navigate to order via the association
var order = orderLine.GetOrder();
What I get basically is a nul...
I'm building a list of properties of a type to include in an export of a collection of that type. I'd like to do this without using strings for property names. Only certain properties of the type are to be included in the list. I'd like to do something like:
exportPropertyList<JobCard>.Add(jc => jc.CompletionDate, "Date of Completion...
In my generic abstract class
class SomeClass<T> where T : ISomeInterface
I have a method that calls my repository and pass a parameter Expression<Func<T, bool>> parameter to tell him the 'where' condition.
As T implements ISomeInterface, the DebugView of the lambda passed brings me something like
...((ISomeInterface)$p).SomeInterfac...
Is it possible to create an inline lambda using boost which always throws an exception?
(this question follows on from "Using boost to create a lambda function which always returns true").
Suppose I have a function which takes some form of predicate:
void Foo( boost::function<bool(int,int,int)> predicate );
If I want to call it with...
In c++0x is there a way to template a lambda function? Or is it inherently too specific to be templated?
I understand that I can define a classic templated class/functor instead but the question is more like : does the language allow templating lambda functions?
...
I have a repository layer that deals with LINQ to SQL autogenerated entities. These eventually get mapped into domain-friendly types on the surface. I'd now like to provide some more sophisticated querying capabilities for the client code, and that client code knows only about the domain object types.
I'd like to implement this with t...
Is it possible to have a C# lambda/delegate that can take a variable number of parameters that can be invoked with a Dynamic-invoke?
All my attempts to use the 'params' keyword in this context have failed.
** UPDATE WITH WORKING CODE FROM ANSWER **
delegate void Foo(params string[] strings);
static void Main(string[] args) ...
Hello,
i have this model on mvc:
public class User
{
public string Name
{
get;
set;
}
public IList<string>RelatedTags
{
get;
set;
}
}
And the following typed view (user) to edit an add a user (AddEdit.aspx view):
<div>
<%: Html.LabelFor(e => e.Name)%>
<%: Html.TextBoxFor(e => e....
I'm making a program to calculate latency from a tcpdump/pcap file and I want to be able to specify rules on the command line to correlate packets -- i.e. find the time taken between sending a packet matching rule A to receiving a packet matching rule B (concrete example would be a FIX NewOrderSingle being sent and a corresponding FIX Ex...
I want to create a generalized helper method for LoadFromXML loading and validation. If the XML I'm loading from is incomplete, I do want it to fail completely without throwing an exception. Currently, my code looks like this (more or less)
public override bool Load(XElement source)
{
return new List<Func<XElement, bool>>
{
...
Disclaimer 1: Crazy pedantic language-bending drivel ahead.
Disclaimer 2: To any clients present or future - I am not billing you for this.
Alright, so this is not really necessary but I'm messing around with creating plugins for xunit.net and an interesting scenario comes up
Currently, the example of the SubSpec extension that shi...
Dear all,
I need use Lambda Expression in my method
public static class QueryableDynamicExtension
{
public static IQueryable<T> DynamicEquals<T>(
this IQueryable<T> query,
string field,
object value)
{
Expression<Func<T, bool>> expr = ???
return query.Where(expr);
}
}...
I have the following code that simply loops looking for a condition and places all matches into a new collection:
ObservableCollection<Device> allDevices = GetAllDevices();
ObservableCollection<Device> matchingDevices = new ObservableCollection<Device>();
foreach (Device device in allDevices )
{
if (device.ID != 5)
matchingD...
Hello,
I'm using MethodCallExpression to record method calls.
public void RegisterInvocation<TSource>(TSource target, Expression<Action<TSource>> selector)
{
...
}
Somewhen later I execute the expression like this:
selector.Compile().Invoke();
And here I have a strange effekt (perhaps I missunderstand something with Method Call...