Download MovieFinder.Scraper/PropertyComparer.cs from niobures/VideoSearch: direct link, hf CLI and curl.
- Browser
- Download file 1.68 kB
-
https://huggingface.co/niobures/VideoSearch/resolve/main/MovieFinder.Scraper/PropertyComparer.cs
- Command line
-
hf download hf://niobures/VideoSearch/MovieFinder.Scraper/PropertyComparer.cs
-
curl -L -o PropertyComparer.cs https://huggingface.co/niobures/VideoSearch/resolve/main/MovieFinder.Scraper/PropertyComparer.cs
1.68 kB
| using System; | |
| using System.Collections; | |
| using System.Collections.Generic; | |
| using System.ComponentModel; | |
| using System.Reflection; | |
| namespace MovieFinder.Scraper | |
| { | |
| public class PropertyComparer<T> : IComparer<T> | |
| { | |
| private readonly IComparer comparer; | |
| private PropertyDescriptor propertyDescriptor; | |
| private int reverse; | |
| public PropertyComparer(PropertyDescriptor property, ListSortDirection direction) | |
| { | |
| this.propertyDescriptor = property; | |
| Type comparerForPropertyType = typeof(Comparer<>).MakeGenericType(property.PropertyType); | |
| this.comparer = (IComparer)comparerForPropertyType.InvokeMember("Default", BindingFlags.Static | BindingFlags.GetProperty | BindingFlags.Public, null, null, null); | |
| this.SetListSortDirection(direction); | |
| } | |
| public int Compare(T x, T y) | |
| { | |
| return this.reverse * this.comparer.Compare(this.propertyDescriptor.GetValue(x), this.propertyDescriptor.GetValue(y)); | |
| } | |
| private void SetPropertyDescriptor(PropertyDescriptor descriptor) | |
| { | |
| this.propertyDescriptor = descriptor; | |
| } | |
| private void SetListSortDirection(ListSortDirection direction) | |
| { | |
| this.reverse = direction == ListSortDirection.Ascending ? 1 : -1; | |
| } | |
| public void SetPropertyAndDirection(PropertyDescriptor descriptor, ListSortDirection direction) | |
| { | |
| this.SetPropertyDescriptor(descriptor); | |
| this.SetListSortDirection(direction); | |
| } | |
| } | |
| } |