Skip to main content
Code Review

Return to Question

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

I am following up on this answer this answer for a scenario that I am currently working on. Like the OP, I am too concerned about the longevity of the code.

public IQueryable<TEntity> EmptyEnumerable()
{
 return Enumerable.Empty<TEntity>().AsQueryable();
}
private Expression<Func<TEntity, bool>> GetFilterExpression(FilterQueryOption filter)
{
 var enumerable = this.EmptyEnumerable();
 var param = Expression.Parameter(typeof(TEntity));
 if(filter != null)
 {
 enumerable = (IQueryable<TEntity>)filter.ApplyTo(enumerable, new ODataQuerySettings());
 var mce = enumerable.Expression as MethodCallExpression;
 if(mce != null)
 {
 var quote = mce.Arguments[1] as UnaryExpression;
 if(quote != null)
 {
 return quote.Operand as Expression<Func<TEntity, bool>>;
 }
 }
 }
 return Expression.Lambda<Func<TEntity, bool>>(Expression.Constant(true), param);
}

My questions are:

  1. Is there anything that I should be checking, which I am not already checking?
  2. Is returning a truth expression a sensible default?

Any refactorings/improvements are welcome.

I am following up on this answer for a scenario that I am currently working on. Like the OP, I am too concerned about the longevity of the code.

public IQueryable<TEntity> EmptyEnumerable()
{
 return Enumerable.Empty<TEntity>().AsQueryable();
}
private Expression<Func<TEntity, bool>> GetFilterExpression(FilterQueryOption filter)
{
 var enumerable = this.EmptyEnumerable();
 var param = Expression.Parameter(typeof(TEntity));
 if(filter != null)
 {
 enumerable = (IQueryable<TEntity>)filter.ApplyTo(enumerable, new ODataQuerySettings());
 var mce = enumerable.Expression as MethodCallExpression;
 if(mce != null)
 {
 var quote = mce.Arguments[1] as UnaryExpression;
 if(quote != null)
 {
 return quote.Operand as Expression<Func<TEntity, bool>>;
 }
 }
 }
 return Expression.Lambda<Func<TEntity, bool>>(Expression.Constant(true), param);
}

My questions are:

  1. Is there anything that I should be checking, which I am not already checking?
  2. Is returning a truth expression a sensible default?

Any refactorings/improvements are welcome.

I am following up on this answer for a scenario that I am currently working on. Like the OP, I am too concerned about the longevity of the code.

public IQueryable<TEntity> EmptyEnumerable()
{
 return Enumerable.Empty<TEntity>().AsQueryable();
}
private Expression<Func<TEntity, bool>> GetFilterExpression(FilterQueryOption filter)
{
 var enumerable = this.EmptyEnumerable();
 var param = Expression.Parameter(typeof(TEntity));
 if(filter != null)
 {
 enumerable = (IQueryable<TEntity>)filter.ApplyTo(enumerable, new ODataQuerySettings());
 var mce = enumerable.Expression as MethodCallExpression;
 if(mce != null)
 {
 var quote = mce.Arguments[1] as UnaryExpression;
 if(quote != null)
 {
 return quote.Operand as Expression<Func<TEntity, bool>>;
 }
 }
 }
 return Expression.Lambda<Func<TEntity, bool>>(Expression.Constant(true), param);
}

My questions are:

  1. Is there anything that I should be checking, which I am not already checking?
  2. Is returning a truth expression a sensible default?

Any refactorings/improvements are welcome.

Source Link

Parsing ODataQueryOptions<T> to Expression<Func<T, bool>>

I am following up on this answer for a scenario that I am currently working on. Like the OP, I am too concerned about the longevity of the code.

public IQueryable<TEntity> EmptyEnumerable()
{
 return Enumerable.Empty<TEntity>().AsQueryable();
}
private Expression<Func<TEntity, bool>> GetFilterExpression(FilterQueryOption filter)
{
 var enumerable = this.EmptyEnumerable();
 var param = Expression.Parameter(typeof(TEntity));
 if(filter != null)
 {
 enumerable = (IQueryable<TEntity>)filter.ApplyTo(enumerable, new ODataQuerySettings());
 var mce = enumerable.Expression as MethodCallExpression;
 if(mce != null)
 {
 var quote = mce.Arguments[1] as UnaryExpression;
 if(quote != null)
 {
 return quote.Operand as Expression<Func<TEntity, bool>>;
 }
 }
 }
 return Expression.Lambda<Func<TEntity, bool>>(Expression.Constant(true), param);
}

My questions are:

  1. Is there anything that I should be checking, which I am not already checking?
  2. Is returning a truth expression a sensible default?

Any refactorings/improvements are welcome.

lang-cs

AltStyle によって変換されたページ (->オリジナル) /