Given a C# Type, Get its Base Classes and Implemented Interfaces

You could write an extension method like this:

public static IEnumerable<Type> GetBaseTypes(this Type type) {
    if(type.BaseType == null) return type.GetInterfaces();

    return Enumerable.Repeat(type.BaseType, 1)
                     .Concat(type.GetInterfaces())
                     .Concat(type.GetInterfaces().SelectMany<Type, Type>(GetBaseTypes))
                     .Concat(type.BaseType.GetBaseTypes());
}

Type has a property BaseType and a method FindInterfaces.

https://msdn.microsoft.com/en-us/library/system.type.aspx

So actually, it almost does have Type.GetAllBaseClassesAndInterfaces, but you have to make two calls instead of one.


More refined answer based on one from SLaks would be:

public static IEnumerable<Type> GetBaseClassesAndInterfaces(this Type type)
{
    return type.BaseType == typeof(object) 
        ? type.GetInterfaces()
        : Enumerable
            .Repeat(type.BaseType, 1)
            .Concat(type.GetInterfaces())
            .Concat(type.BaseType.GetBaseClassesAndInterfaces())
            .Distinct();
}