I am calling:
form = new FormFor<Project>()
.Set(x => x.Name, "hi");
where Project has a field called Name and FormFor’s code is:
public class FormFor<TEntity> where TEntity : class
{
FormCollection form;
public FormFor()
{
form = new FormCollection();
}
public FormFor<TEntity> Set(Expression<Func<TEntity>> property, string value)
{
form.Add(property.PropertyName(), value);
return this;
}
}
but it keeps telling me Delegate 'System.Func<ProjectSupport.Core.Domain.Project>' does not take 1 arguments and I am unsure why. Could anyone shed some light on it for me?
It’s trying to convert this lambda expression:
into an
Expression<Func<TEntity>>.Let’s ignore the expression tree bit for the moment – the delegate type
Func<TEntity>represents a delegate which takes no arguments, and returns aTEntity. Your lambda expressionx => x.Nameclearly is expecting a parameter (x). I suspect you wantor something similar, but it’s not really clear what you’re trying to do.