public static bool IsNestedWithin(this TypeReference type, TypeDefinition possibleAncestorType) { if (type == null) { return false; } while (type.DeclaringType != null) { if (type.DeclaringType.Resolve().FullName == possibleAncestorType.FullName) { return true; } type = type.DeclaringType; } return false; }