Proper serialization of an object implementing IEnumerable<T>

This commit fixes an issue whereby child items of a class
implementing IEnumerable{T} would not get a __type field,
thereby making it impossible to deserialize the output.
The fix moved code that was meant to run on top of IEnumerable{T}
instances to a place where it will be checked in all circumstances.
Previously it would only be called when an object implements
IDictionary{K,V}.