private static int GetClassDepth(Type type) { int depth = 0; Type objectType = typeof(object); while (type != objectType) { type = type.BaseType; ++depth; } return depth; }