Код: Выделить всё
public void Test(T reference, T same, T differentOrGreater)
{
var comparisonInterface = typeof(T)
.GetInterfaces()
.FirstOrDefault(
i => i.IsGenericType &&
i.GetGenericTypeDefinition() == typeof(IComparisonOperators));
this.GetType()
.GetMethod(nameof(this.CheckComparisonOperators),
BindingFlags.NonPublic | BindingFlags.Instance)!
.MakeGenericMethod(typeof(T))
.Invoke(this, [reference, same, differentOrGreater]);
}
private void CheckComparisonOperators(T reference, T same, T greater)
where T : IComparisonOperators
{
// do stuff
}
public record BaseSize(uint Value) : IComparisonOperators
where T : BaseSize
{
// implementation
}
public record DerivedSize(uint Value) : BaseSize(Value);
Код: Выделить всё
Test(new DerivedSize(1), new DerivedSize(1), new DerivedSize(2));
Подробнее здесь: https://stackoverflow.com/questions/798 ... ericmethod