using System.Collections.Generic;
using System.Collections;
using System.Collections.ObjectModel;
static bool IsSelfComparable(Type type) => type
.Any(t => t.IsGenericType && t.GetGenericTypeDefinition() == typeof(IComparable<>) && t.GetGenericArguments()[0] == type);
public void Foo(IEnumerable<Type> types)
foreach (var type in types)
if (!IsSelfComparable(type))
throw new ArgumentException($"Invalid type {type}");
public static void Main()
var fooClass = new FooClass();
fooClass.Foo([typeof(int), typeof(DateTime), typeof(string)]);
fooClass.Foo([typeof(object)]);
catch (ArgumentException ex)
Console.WriteLine("Caught expected exception {0}", ex.Message);