It would be easy to analyze an expression-tree containing a bunch of assignments, but unfortunately, C# doesn't support the creation of expression-trees with assignments or statements through lambdas yet, as the compiler errors indicate.
I suggest you construct a custom object that can hold a list of (member access lambda, object) tuples and use that instead.
For example, you should be able to create a class that would allow for this syntax:
var list = new AssignmentList<MyBunchOfProps>
{
{ o => o.SomeProperty, 1 },
{ o => o.AnotherProperty, "two" }
};
Here's an example implementation for this:
public class AssignmentList<T> : IEnumerable<Tuple<LambdaExpression, object>>
{
private readonly List<Tuple<LambdaExpression, object>> _list
= new List<Tuple<LambdaExpression, object>>();
public void Add<TProperty>(Expression<Func<T, TProperty>> selector, TProperty value)
{
_list.Add(Tuple.Create<LambdaExpression, object>(selector, value));
}
public IEnumerator<Tuple<LambdaExpression, object>> GetEnumerator()
{
return _list.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}