Skip to content

Instantly share code, notes, and snippets.

@wullemsb
Created March 2, 2026 19:28
Show Gist options
  • Select an option

  • Save wullemsb/04330b2c76c15bcff81e6273d8074314 to your computer and use it in GitHub Desktop.

Select an option

Save wullemsb/04330b2c76c15bcff81e6273d8074314 to your computer and use it in GitHub Desktop.
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;
}
}
}
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