aboutsummaryrefslogtreecommitdiff
path: root/BackEnd/Timeline/Models
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2021-01-31 16:07:07 +0800
committercrupest <crupest@outlook.com>2021-01-31 16:07:07 +0800
commit27e6b7be9bce006da6aae651d9903573cf3fd180 (patch)
treecd7fbb5ad97d16bf9d301fd55fe6bf4da6e25160 /BackEnd/Timeline/Models
parent8b244ef8ad5f7c333fee4c39e3041846b87f0740 (diff)
downloadtimeline-27e6b7be9bce006da6aae651d9903573cf3fd180.tar.gz
timeline-27e6b7be9bce006da6aae651d9903573cf3fd180.tar.bz2
timeline-27e6b7be9bce006da6aae651d9903573cf3fd180.zip
...
Diffstat (limited to 'BackEnd/Timeline/Models')
-rw-r--r--BackEnd/Timeline/Models/Validation/StringSetValidator.cs40
1 files changed, 40 insertions, 0 deletions
diff --git a/BackEnd/Timeline/Models/Validation/StringSetValidator.cs b/BackEnd/Timeline/Models/Validation/StringSetValidator.cs
new file mode 100644
index 00000000..363ece10
--- /dev/null
+++ b/BackEnd/Timeline/Models/Validation/StringSetValidator.cs
@@ -0,0 +1,40 @@
+using System;
+using System.Linq;
+
+namespace Timeline.Models.Validation
+{
+ public class StringSetValidator : Validator<string>
+ {
+ public StringSetValidator(params string[] set)
+ {
+ Set = set;
+ }
+
+#pragma warning disable CA1819 // Properties should not return arrays
+ public string[] Set { get; set; }
+#pragma warning restore CA1819 // Properties should not return arrays
+
+ protected override (bool, string) DoValidate(string value)
+ {
+ var contains = Set.Contains(value, StringComparer.OrdinalIgnoreCase);
+ if (!contains)
+ {
+ return (false, "Not a valid value.");
+ }
+ else
+ {
+ return (true, GetSuccessMessage());
+ }
+ }
+ }
+
+ [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter,
+ AllowMultiple = false)]
+ public class ValidationSetAttribute : ValidateWithAttribute
+ {
+ public ValidationSetAttribute(params string[] set) : base(new StringSetValidator(set))
+ {
+
+ }
+ }
+}