Это можно преобразовать массив params Expression<Func<TModel, object>>[] includeProperties
Преобразование массива Expression <Func <TModel, объект >> [] в список List <System.Reflection.PropertyInfo>
в массив List<System.Reflection.PropertyInfo> propertiesInfo
?
Если да, объясните, как я могу это сделать?
TModel представляет собой класс
EDITED:
Моя цель этого действия в том, что я могу назначить только некоторые свойства объекта к другому объекту. Мой метод для этой цели:
public static void Assign(this object destination, object source, List<System.Reflection.PropertyInfo> includeProperties)
{
if (destination is IEnumerable && source is IEnumerable)
{
var dest_enumerator = (destination as IEnumerable).GetEnumerator();
var src_enumerator = (source as IEnumerable).GetEnumerator();
while (dest_enumerator.MoveNext() && src_enumerator.MoveNext())
dest_enumerator.Current.Assign(src_enumerator.Current);
}
else
{
//var destProperties = destination.GetType().GetProperties();
foreach (var sourceProperty in source.GetType().GetProperties())
{
foreach (PropertyInfo destProperty in includeProperties)
{
if (destProperty.Name == sourceProperty.Name && destProperty.PropertyType.IsAssignableFrom(sourceProperty.PropertyType))
{
destProperty.SetValue(destination, sourceProperty.GetValue(source, new object[] { }), new object[] { });
break;
}
}
}
}
}
другой метод:
public virtual void Update(object viewModel, params Expression<Func<TModel, object>>[] includeProperties)
{
List<PropertyInfo> pList = new List<PropertyInfo>();
foreach (var prop in includeProperties)
{
//Todo: I should convert prop to PropertyInfo and then add to pList
}
using (new EFUnitOfWorkFactory().Create())
{
TModel model = new TModel();
model.Assign(viewModel, pList);
RepositoryContainer<TRepository>().Update(model);
}
}
Я не понимаю: как вы ожидаете получить свойство из 'Func'? возвращает ли функция значение свойства? –
Blorgbeard