1
+ // Licensed to the .NET Foundation under one or more agreements.
2
+ // The .NET Foundation licenses this file to you under the MIT license.
3
+
4
+ #nullable disable
5
+
6
+ using System ;
7
+ using System . Collections . Generic ;
8
+ using System . ComponentModel . DataAnnotations ;
9
+ using System . Globalization ;
10
+
11
+ namespace Microsoft . Diagnostics . Tools . Monitor . CollectionRules . Options
12
+ {
13
+ partial class CollectionRuleOptions : IValidatableObject
14
+ {
15
+ IEnumerable < ValidationResult > IValidatableObject . Validate ( ValidationContext validationContext )
16
+ {
17
+ List < ValidationResult > results = new ( ) ;
18
+
19
+ // ErrorList is populated by incorrectly using templates - this will be empty if all templates names can be resolved or if templates are not used.
20
+ // results.AddRange(ErrorList);
21
+ foreach ( var error in ErrorList )
22
+ {
23
+ results . Add ( new ValidationResult ( error . Error , [ error . MemberName ] ) ) ;
24
+ }
25
+
26
+ if ( results . Count > 0 )
27
+ {
28
+ return results ;
29
+ }
30
+
31
+ // ValidationContext filtersContext = new(Filters, validationContext, validationContext.Items);
32
+ // filtersContext.MemberName = nameof(Filters);
33
+ // ValidationHelper.TryValidateItems(Filters, filtersContext, results);
34
+
35
+ // if (null != Trigger)
36
+ // {
37
+ // ValidationContext triggerContext = new(Trigger, validationContext, validationContext.Items);
38
+ // triggerContext.MemberName = nameof(Trigger);
39
+ // Validator.TryValidateObject(Trigger, triggerContext, results);
40
+ // }
41
+
42
+ // ValidationContext actionsContext = new(Actions, validationContext, validationContext.Items);
43
+ // actionsContext.MemberName = nameof(Actions);
44
+ // ValidationHelper.TryValidateItems(Actions, actionsContext, results);
45
+
46
+ var actionNames = new HashSet < string > ( StringComparer . Ordinal ) ;
47
+ foreach ( CollectionRuleActionOptions option in Actions )
48
+ {
49
+ if ( ! string . IsNullOrEmpty ( option . Name ) && ! actionNames . Add ( option . Name ) )
50
+ {
51
+ results . Add ( new ValidationResult (
52
+ string . Format ( CultureInfo . CurrentCulture , Strings . ErrorMessage_DuplicateActionName , option . Name ) ,
53
+ new [ ] { nameof ( option . Name ) } ) ) ;
54
+ }
55
+ }
56
+
57
+ return results ;
58
+ }
59
+ }
60
+ }
0 commit comments