Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

59 lines (51 sloc) 1.878 kb
using System;
using System.Linq.Expressions;
using FubuCore.Reflection;
using FubuFastPack.Domain;
namespace FubuFastPack.Querying
{
public class SingleEntityFilter<T> : IDataSourceFilter<T> where T : DomainEntity
{
private readonly T _domainEntity;
public SingleEntityFilter(T domainEntity)
{
CanView = true;
_domainEntity = domainEntity;
DenyingRestriction = null;
}
public void WhereEqual(Expression<Func<T, object>> property, object value)
{
if (!CanView) return;
var entityValue = ReflectionHelper.GetAccessor(property).GetValue(_domainEntity);
if (ReferenceEquals(entityValue, null))
{
if (!ReferenceEquals(value, null)) CanView = false;
}
else
{
if (!entityValue.Equals(value)) CanView = false;
}
}
public void WhereNotEqual(Expression<Func<T, object>> property, object value)
{
if (!CanView) return;
var entityValue = ReflectionHelper.GetAccessor(property).GetValue(_domainEntity);
if (ReferenceEquals(entityValue, null))
{
if (ReferenceEquals(value, null)) CanView = false;
}
else
{
if (entityValue.Equals(value)) CanView = false;
}
}
public void ApplyRestriction(IDataRestriction<T> restriction)
{
restriction.Apply(this);
if (!CanView && DenyingRestriction == null) DenyingRestriction = restriction;
}
// could be useful for diagnostics
public IDataRestriction<T> DenyingRestriction { get; set; }
public bool CanView { get; private set; }
}
}
Jump to Line
Something went wrong with that request. Please try again.