diff options
author | crupest <crupest@outlook.com> | 2020-03-10 16:01:09 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-03-10 16:01:09 +0800 |
commit | 3267e698c644ec638af42b782b6848dc27467f8b (patch) | |
tree | f71188192238770e03ea2bf7d0b1e3485e4d219c /Timeline/Models | |
parent | aa6b13ad8d7713087c635d52817f469c1fab8c45 (diff) | |
download | timeline-3267e698c644ec638af42b782b6848dc27467f8b.tar.gz timeline-3267e698c644ec638af42b782b6848dc27467f8b.tar.bz2 timeline-3267e698c644ec638af42b782b6848dc27467f8b.zip |
...
Diffstat (limited to 'Timeline/Models')
-rw-r--r-- | Timeline/Models/Timeline.cs | 2 | ||||
-rw-r--r-- | Timeline/Models/Validation/GeneralTimelineNameValidator.cs | 33 |
2 files changed, 35 insertions, 0 deletions
diff --git a/Timeline/Models/Timeline.cs b/Timeline/Models/Timeline.cs index e2ff525e..6d4c924d 100644 --- a/Timeline/Models/Timeline.cs +++ b/Timeline/Models/Timeline.cs @@ -55,7 +55,9 @@ namespace Timeline.Models public DateTime LastUpdated { get; set; } = default!;
}
+#pragma warning disable CA1724 // Type names should not match namespaces
public class Timeline
+#pragma warning restore CA1724 // Type names should not match namespaces
{
public string Name { get; set; } = default!;
public string Description { get; set; } = default!;
diff --git a/Timeline/Models/Validation/GeneralTimelineNameValidator.cs b/Timeline/Models/Validation/GeneralTimelineNameValidator.cs new file mode 100644 index 00000000..e1c96fbd --- /dev/null +++ b/Timeline/Models/Validation/GeneralTimelineNameValidator.cs @@ -0,0 +1,33 @@ +using System;
+
+namespace Timeline.Models.Validation
+{
+ public class GeneralTimelineNameValidator : Validator<string>
+ {
+ private readonly UsernameValidator _usernameValidator = new UsernameValidator();
+ private readonly TimelineNameValidator _timelineNameValidator = new TimelineNameValidator();
+
+ protected override (bool, string) DoValidate(string value)
+ {
+ if (value.StartsWith('@'))
+ {
+ return _usernameValidator.Validate(value.Substring(1));
+ }
+ else
+ {
+ return _timelineNameValidator.Validate(value);
+ }
+ }
+ }
+
+ [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter,
+ AllowMultiple = false)]
+ public class GeneralTimelineNameAttribute : ValidateWithAttribute
+ {
+ public GeneralTimelineNameAttribute()
+ : base(typeof(GeneralTimelineNameValidator))
+ {
+
+ }
+ }
+}
|