Fixed the generation of 'ToInternal' to check for null only fields of a ref type.

Part of the patch by @ddobrev.