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()); }
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 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); }