-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathFilter.cs
51 lines (45 loc) · 1.66 KB
/
Filter.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System;
using System.Runtime.CompilerServices;
[assembly: InternalsVisibleTo("DataPipelineTools.Tests")]
namespace SqlCollaborative.Azure.DataPipelineTools.Common
{
public class Filter<T>
{
public string PropertyName { get; set; }
public Type PropertyType { get; set; }
public string Operator { get; set; }
public string Value { get; set; }
public bool IsValid { get; set; } = false;
public string ErrorMessage { get; set; } = null;
public string GetDynamicLinqString()
{
switch (Operator)
{
case "like":
var RegexMatchFunc = $"{nameof(DynamicLinqUtils)}.{nameof(DynamicLinqUtils.IsRegexMatch)}";
return $"{RegexMatchFunc}({PropertyName}, @0)";
default:
return $"{PropertyName} {Operator} @0";
}
}
public object GetDynamicLinqValue()
{
// Avoid throwing trying to do an invalid cast
if (!IsValid)
return null;
switch (PropertyType.Name)
{
case nameof(DateTime):
return DateTime.Parse(Value);
case nameof(DateTimeOffset):
return DateTimeOffset.Parse(Value);
default:
return Operator == "like" ? Value.Replace("*", ".*") : Value;
}
}
#region Newtonsoft.Json serialization methods
public bool ShouldSerializeIsValid() => false;
public bool ShouldSerializePropertyType() => false;
#endregion Newtonsoft.Json serialization methods
}
}