Skip to content

Instantly share code, notes, and snippets.

@trnktms
Last active January 6, 2017 16:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trnktms/a67378b9c75c395a7292af4a57322e5d to your computer and use it in GitHub Desktop.
Save trnktms/a67378b9c75c395a7292af4a57322e5d to your computer and use it in GitHub Desktop.
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