I'm writing an ASP.NET MVC 2 site where I have defined a custom ViewModel that I'm trying to use in a View. Unfortunately, I'm running into an error when using the ViewModel through a strongly-typed lambda expression.
My Code
Here's my ViewModel:
[CompareProperties(ComparisonProperty1="EmailAddress", ComparisonProperty2="Confirm...
public void aMethod<T>(Expression<Func<T, object>> lambda)
{
......
}
aMethod<User>(x=> x.UserId)
User is my custom class, members of his UserId int type...
I want the lambda expression x => x.UserId
But in the way, I get is x => Convert (x.UserId)
Therefore, the following operations can not, I need to ensure that my expression ...
e.g.
x => x.UserId > 5 &&
x.Name.StartWith("S") &&
x.Name.EndWith("D") &&
x.Name.Contains("x")
to
it.UserId > 5 And it.Name like 'S%' And it.Name like '%D' And it.Name like '%x%'
...
I want to be able to do this:
var test = SomeMethod(s => s.SomeMethod);
I can make it work with properties by making the method signature look like this:
SomeMethod<TProperty>(Expression<Func<T, TProperty>> expression)
How can I make it work with methods? I know this is simple, I'm just missing something small.
...
The MSDN magazine article by Josh Smith on MVVM contains a lambda expression I don't completely understand. What is the purpose of param in this code?
_saveCommand = new RelayCommand(param => this.Save(),
param => this.CanSave );
Translated to my preferred language VB it's:
Dim saveAction as New Action(Of Object)(Addr...
I'm using the following method to show a modeless Message Box.
public void ShowMessageBox(string Message)
{
var thread = new Thread(
() =>
{
MessageBox.Show(Message);
});
thread.Start();
}
The "() => {...}" is something I've never seen before. What is the name for this code pattern?
Also, thread.Start start...
Please look at the following C++0x lambda related code:
typedef uint64_t (*WEIGHT_FUNC)(void* param);
typedef std::map<std::string, WEIGHT_FUNC> CallbackTable;
CallbackTable table;
table["rand_weight"] = [](void* param) -> uint64_t
{
return (rand() % 100 + 1);
};
I got an error (in Visual Studio 2010) that the lambda couldn't be co...
The error is in this code:
//myutil.h
template <class T, class predicate>
T ConditionalInput(LPSTR inputMessage, LPSTR errorMessage, predicate condition);
//myutil.cpp
template <class T, class Pred>
T ConditionalInput(LPSTR inputMessage, LPSTR errorMessage, Pred condition)
{
T input
cout<< inputMessage;
cin>...
How can I use PHP 5.3 Closures like We use Blocks in Ruby.
I never used 'for' Loop in Ruby due to using Blocks with 'each' 'find_all' 'inject' Methods.
How can I use PHP 5.3 Closures like Ruby Blocks and say bye-bye to 'for' Loops :)
Like Between { and } is a Closure(or Block or Anonymous Function)
fruit = %w[apple banana orange]
frui...
I am writing a service to take a collection of objects of a particular type and output its primitive, string, and DateTime types to a string in CSV Format. I have both of the below statements working. I find the the lambda based version to be much cleaner.
Magic String Version
string csv = new ToCsvService<DateTime>(objs)
.Exclude(...
Is it possible to create an expression tree that directly calls a method? For example, consider the following method:
public static int MyFunc(int a, int b)
{
return a + b;
}
I would like to create an expression tree that calls MyFunc with parameters a=1 and b=2. One way to accomplish this is with reflection:
var c1 = Expression....
I'm having a bit of trouble doing an inline .GroupBy() and .Sum() action.
I have a subset of data obtained via a let so it's return type is already anonymous. Hopefully there's enough code in this sample to show what I'm trying to achieve...
from r in Repo.R
join f in Repo.F
on f.ID equals r.FFK
let totalB = Repo.B
.Join(
...
I'm writing code that evaluates .NET Expression trees. I'm trying to create a C# 4 test to exercise my handling of an ExpressionType.Index, but I can't figure out how to create that type of expression through a LambdaExpression. No matter what I try, the expression comes out as an ExpressionType.Call or ExpressionType.ArrayIndex. For ...
Hi,
ReSharper suggests we change:
System.Net.ServicePointManager.ServerCertificateValidationCallback +=
delegate(object sender, X509Certificate certificate, X509Chain chain,
SslPolicyErrors sslPolicyErrors)
{
return true;
};
Into:
System.Net.ServicePointManager.ServerCertificateValidationCallback +=
(sender, cert...
Hi,
i have this linq to entities query:
c.CreateQuery<T_Hotels>("T_Hotels").Where(item => item.Id > 0).GroupBy(item => new { item.Location, item.Name }).Select(group => new { group.Key, Total = group.Sum(item => item.Id) })
I want to implement everything in a method of a class Helper, how declare the expressions of GroupBy and Select...
We have a project using Fluent NHibernate. There is an object called BluePart with a property of Oem of type Oem.
public class BluePart : DomainEntity
{
...
public virtual Oem Oem { get; set; }
}
The Oem object has several properties including OemCode and OemDescription.
public class Oem : DomainEntity
{
...
public vi...
I'm trying to use an already existing Expression building class that I made when trying to do a select clause, but I'm not sure how to attach the expression to the expression tree for the Select, I tried doing the following:
var catalogs = matchingCatalogs.Select(c => new
{
c.CatalogID,
...
I am trying to use a lambda to pass in place of a function pointer but VS2010 can't seem to convert it. I have tried using std::function like this and it crashes and I have no idea if I am doing this right!
#include <windows.h>
#include <conio.h>
#include <functional>
#include <iostream>
#include <concrt.h>
void main()
{
std::f...
I'm curious on how the NHibernate team has solved the QueryOver syntax, so that it works with intellisense and validation at compile time?
According to http://nhforge.org/blogs/nhibernate/archive/2009/12/17/queryover-in-nh-3-0.aspx they make use of extension methods and lambda expressions, but I've tried looking through the source but i...
Hi there
I have a class.
public class MedicalRequest
{
private int id
private IList<MedicalDays> Days
private string MedicalUser
...
}
and another
public class MedicalDays
{
private int id;
private DateTime? day
private MedicalRequest request
...
}
I have the MedicalUser so I'm able to select an
I...