25 lines
762 B
C#
25 lines
762 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Portoa.Persistence;
|
|
|
|
namespace VideoGameQuotes.Api {
|
|
public abstract class CriterionHandler<T> where T : Entity<int> {
|
|
public IEnumerable<Func<T, bool>> HandleCriterion(IEnumerable<object> values) {
|
|
foreach (var value in values) {
|
|
if (value is int) {
|
|
yield return HandleInteger((int)value);
|
|
} else {
|
|
yield return HandleString((string)value);
|
|
}
|
|
}
|
|
}
|
|
|
|
protected virtual Func<T, bool> HandleInteger(int value) {
|
|
throw new ApiException(string.Format("The value \"{0}\" is invalid", value));
|
|
}
|
|
|
|
protected virtual Func<T, bool> HandleString(string value) {
|
|
throw new ApiException(string.Format("The value \"{0}\" is invalid", value));
|
|
}
|
|
}
|
|
} |