Ну, например так:
| Код | static Action<T, TValue> GetPropertySetter<T, TValue>(string propertyName) { Type elementType = typeof(T); var tp = typeof(T).GetProperty(propertyName); ParameterExpression targetExp = Expression.Parameter(typeof(T), "target"); ParameterExpression valueExp = Expression.Parameter(typeof(TValue), "value");
MemberExpression propExp = Expression.Property(targetExp, tp); BinaryExpression assignExp = Expression.Assign(propExp, valueExp);
var action = Expression.Lambda<Action<T, TValue>>(assignExp, targetExp, valueExp); return action.Compile(); }
|
и использовать:
| Код | var r = GetPropertySetter<DTO, string>("MyPropertyName"); r(dto, "134");
|
пойдет? |