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);
            }
        }
        private static string SerializeColumnToString <T>(T column)
        {
            if (column == null)
            {
                return("null");
            }

            var columnType = column.GetType();
            var result     = new StringBuilder();

            if (EntityTypeDescriptor.IsSimpleType(columnType) || EntityTypeDescriptor.IsNullableType(columnType))
            {
                result.Append(column);
            }
            else if (EntityTypeDescriptor.IsSupportedEnumerable(columnType))
            {
                var enumerable = column as IEnumerable;

                foreach (var item in enumerable)
                {
                    result.AppendFormat("{0},", SerializeColumnToString(item));
                }
            }
            else
            {
                var typeDescription = EntityTypeDescriptor.GetTypeDescription(columnType);
                foreach (var item in typeDescription.Columns)
                {
                    result.AppendFormat("{0}={1}\n", item.ColumnAttribute.Name ?? item.ColumnInfo.Name,
                                        SerializeColumnToString(item.ColumnInfo.GetValue(column, null)));
                }
            }

            return(result.ToString());
        }
        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);
        }