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<MemberInfo> IgnoreProperties { get; private set; }
public List<MemberInfo> IncludeProperties { get; private set; }
public EntitySerializationStrategy()
{
IgnoreProperties = new List<MemberInfo>();
IncludeProperties = new List<MemberInfo>();
}
public EntitySerializationStrategy Ignore<T>(Expression<Func<T>> 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<T>(Expression<Func<T>> 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;
}
}
}