Created
March 2, 2026 19:28
-
-
Save wullemsb/04330b2c76c15bcff81e6273d8074314 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private class FilterComparer : IComparer<Filter> | |
| { | |
| public int Compare(Filter x, Filter y) | |
| { | |
| // Nulls always have to be less than non-nulls | |
| if (x == null && y == null) | |
| { | |
| return 0; | |
| } | |
| if (x == null) | |
| { | |
| return -1; | |
| } | |
| if (y == null) | |
| { | |
| return 1; | |
| } | |
| // Sort first by order... | |
| if (x.Order < y.Order) | |
| { | |
| return -1; | |
| } | |
| if (x.Order > y.Order) | |
| { | |
| return 1; | |
| } | |
| // ...then by scope | |
| if (x.Scope < y.Scope) | |
| { | |
| return -1; | |
| } | |
| if (x.Scope > y.Scope) | |
| { | |
| return 1; | |
| } | |
| return 0; | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private IEnumerable<Filter> RemoveDuplicates(IEnumerable<Filter> filters) | |
| { | |
| HashSet<Type> visitedTypes = new HashSet<Type>(); | |
| foreach (Filter filter in filters) | |
| { | |
| object filterInstance = filter.Instance; | |
| Type filterInstanceType = filterInstance.GetType(); | |
| if (!visitedTypes.Contains(filterInstanceType) || AllowMultiple(filterInstance)) | |
| { | |
| yield return filter; | |
| visitedTypes.Add(filterInstanceType); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment