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);
            }
        }
Beispiel #2
0
        private static object ResolveColumn(ColumnAttribute columnAttribute, MemberExpression expression, IEnumerable <NodeReference> references)
        {
            if (columnAttribute != null)
            {
                foreach (var nodeReference in references)
                {
                    nodeReference.AppendSubscript(columnAttribute.Name ?? expression.Member.Name);
                }
                return(references);
            }

            if (EntityTypeDescriptor.IsSupportedEnumerable(expression.Expression.Type) && expression.Member.Name == "Count")
            {
                var result = references.Select(DatabaseManager.GetEnumerableCount).ToList();
                return(result);
            }

            if (EntityTypeDescriptor.IsArrayType(expression.Expression.Type) && expression.Member.Name == "Length")
            {
                var result = references.Select(DatabaseManager.GetEnumerableCount).ToList();
                return(result);
            }

            if (EntityTypeDescriptor.IsArrayType(expression.Expression.Type) && expression.Member.Name == "LongLength")
            {
                var result = references.Select(DatabaseManager.GetEnumerableCount).ToList();
                return(result);
            }

            if (EntityTypeDescriptor.IsNullableType(expression.Expression.Type) && expression.Member.Name == "Value")
            {
                return(references);
            }

            var parentType = expression.Expression.Type;
            var data       = DatabaseManager.ReadNodes(references, parentType) as IEnumerable;

            return(ProcessLoadedEntityMembers(data, expression));
        }
        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);
        }