public void Test<T>(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>(T reference, T same, T greater) where T : IComparisonOperators<T, T, bool> { // do stuff } public record BaseSize<T>(uint Value) : IComparisonOperators<T, BaseSize<T>, bool> where T : BaseSize<T> { // implementation } public record DerivedSize(uint Value) : BaseSize<DerivedSize>(Value);

The call works fine with BaseSize but fails for DerivedSize:

Test(new DerivedSize(1), new DerivedSize(1), new DerivedSize(2));

how can I fix this?

codymanix's user avatar

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.