You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
#rnx #rb none #jira none #ROBOMERGE-OWNER: ben.marsh #ROBOMERGE-AUTHOR: ryan.durand #ROBOMERGE-SOURCE: CL 10869242 in //Fortnite/Release-12.00/... via CL 10869536 via CL 10870960 #ROBOMERGE-BOT: BUILD (Main -> Dev-Build) (v624-10872983) [CL 10876684 by ryan durand in Dev-Build branch]
45 lines
1.3 KiB
C#
45 lines
1.3 KiB
C#
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
|
|
namespace Timing_Data_Investigator
|
|
{
|
|
public class PropertyComparer<TClassType> : IComparer<TClassType>
|
|
{
|
|
private string sCompareProperty;
|
|
private bool bSortDescending;
|
|
|
|
public PropertyComparer(string CompareProperty, bool SortDescending)
|
|
{
|
|
sCompareProperty = CompareProperty;
|
|
bSortDescending = SortDescending;
|
|
}
|
|
|
|
public int Compare(TClassType x, TClassType y)
|
|
{
|
|
PropertyInfo ComparePropertyInfo = typeof(TClassType).GetProperties().FirstOrDefault(p => p.Name == sCompareProperty);
|
|
if (ComparePropertyInfo == null)
|
|
{
|
|
throw new InvalidOperationException($"Class '{nameof(TClassType)}' does not contain a property named '{sCompareProperty}'!");
|
|
}
|
|
|
|
if (!ComparePropertyInfo.PropertyType.GetInterfaces().Any(i => i.Name.Contains("IComparable")))
|
|
{
|
|
throw new InvalidOperationException($"Property type '{ComparePropertyInfo.PropertyType.Name}' is not an IComparable!");
|
|
}
|
|
|
|
IComparable xPropValue = ComparePropertyInfo.GetValue(x) as IComparable;
|
|
IComparable yPropValue = ComparePropertyInfo.GetValue(y) as IComparable;
|
|
if (bSortDescending)
|
|
{
|
|
return yPropValue.CompareTo(xPropValue);
|
|
}
|
|
|
|
return xPropValue.CompareTo(yPropValue);
|
|
}
|
|
}
|
|
}
|