private static void WriteItem <T>(T item, NodeReference node)
        {
            var entityType = item.GetType();

            if (EntityTypeDescriptor.IsSimpleType(entityType))
            {
                if (item != null)
                {
                    node.Set(item.ToString());
                }
            }
            else if (EntityTypeDescriptor.IsSimpleNullableType(entityType))
            {
                node.Set(item != null ? item.ToString() : null);
            }
            else if (EntityTypeDescriptor.IsArrayType(entityType))
            {
                WriteArray(node, item as Array);
            }
            else if (EntityTypeDescriptor.IsSupportedEnumerable(entityType))
            {
                var items = item as IEnumerable;

                if (items != null)
                {
                    WriteEnumerable(node, items);
                }
            }
            else
            {
                WriteComplexEntity(item, node);
            }
        }
        internal static object ReadNode(NodeReference node, Type elementType)
        {
            object instance;

            if (EntityTypeDescriptor.IsSimpleType(elementType) || EntityTypeDescriptor.IsSimpleNullableType(elementType))
            {
                var nodeValue = node.GetObject();
                instance = ConvertValue(nodeValue, elementType);
            }
            else if (EntityTypeDescriptor.IsArrayType(elementType))
            {
                instance = ReadArray(node, elementType);
            }
            else if (EntityTypeDescriptor.IsSupportedEnumerable(elementType))
            {
                instance = ReadEnumerable(node, elementType);
            }
            else
            {
                instance = ReadComplexNode(node, elementType);
            }

            return(instance);
        }