-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPreventQueryAttribute.cs
31 lines (27 loc) · 1.02 KB
/
PreventQueryAttribute.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
namespace Crud.Api.Attributes
{
/// <summary>
/// Decorate a property to prevent Query operators.
/// </summary>
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
public class PreventQueryAttribute : Attribute
{
private HashSet<String> _preventedOperators;
/// <summary>
/// Specific Query operators to prevent may be specified. If no operators are specified, all Query operators are prevented. Suggest using <see cref="QueryModels.Operator"/> constants.
/// </summary>
/// <param name="operators">Query operators to be prevented.</param>
public PreventQueryAttribute(params String[] operators)
{
_preventedOperators = new HashSet<string>(operators);
}
public Boolean AllowsOperator(String @operator)
{
if (_preventedOperators.Count == 0)
return false;
if (_preventedOperators.Contains(@operator))
return false;
return true;
}
}
}