Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
namespace YourProject.Extensions
{
public static class ExperienceEditor
{
public static Expression<Func<T, object>>[] GetAllEditFrameFields<T>() where T : IGlassBase
{
var propertyNames = typeof(T).GetProperties().Select(p => p.Name);
var expressions = new List<Expression<Func<T, object>>>();
foreach (var propertyName in propertyNames)
{
var param = Expression.Parameter(typeof(T), "model");
var body = Expression.Convert(Expression.PropertyOrField(param, propertyName), typeof(object));
expressions.Add(Expression.Lambda<Func<T, object>>(body, param));
}
return expressions.ToArray();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment