Remove code duplication in TypeExtensions