using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Reflection; using System.Text; using System.Threading.Tasks; namespace Tango.BL.Serialization { public class EntitySerializationStrategy { public List IgnoreProperties { get; private set; } public List IncludeProperties { get; private set; } public EntitySerializationStrategy() { IgnoreProperties = new List(); IncludeProperties = new List(); } public EntitySerializationStrategy Ignore(Expression> propertyLambda) { var me = propertyLambda.Body as MemberExpression; if (me == null) { throw new ArgumentException("You must pass a lambda of the form: '() => Class.Property' or '() => object.Property'"); } return Ignore(me.Member); } public EntitySerializationStrategy Ignore(MemberInfo memberInfo) { IgnoreProperties.Add(memberInfo); return this; } public EntitySerializationStrategy Include(Expression> propertyLambda) { var me = propertyLambda.Body as MemberExpression; if (me == null) { throw new ArgumentException("You must pass a lambda of the form: '() => Class.Property' or '() => object.Property'"); } return Include(me.Member); } public EntitySerializationStrategy Include(MemberInfo memberInfo) { IncludeProperties.Add(memberInfo); IgnoreProperties.Remove(memberInfo); return this; } } }