Item ItemBuilder(Type template_type, object data_source) { var data = new List <Data>(DataBuilder.GetDatasFor(template_type, data_source)); var embedded_type_infos = TemplateType.get_public_writable_instance_properties().Where(x => x.PropertyType.Namespace == "System.Collections.Generic"); var embedded_collection = new List <EmbeddedCollection>(); foreach (var embedded_type_info in embedded_type_infos) { var property_name = embedded_type_info.Name; var property_value = data_source.try_get_property_value(property_name); var embedded_items = new List <Item>(); foreach (var element in (IEnumerable)property_value) { var embedded_item = new Item(); embedded_item.data = DataBuilder.GetDatasFor(element.GetType(), element); embedded_item.links = CreateLinks(element); embedded_items.Add(embedded_item); } embedded_collection.Add(new EmbeddedCollection { name = property_name, items = embedded_items }); } var item = new Item { data = data, links = new List <Link>(), embedded = embedded_collection }; return(item); }
public IJsonCollectionConfiguration WithSortingFields <SortingModel>() { var query = new Query(); var collection = Configuration.Collection; var filter = query.filter; filter.href = collection.href; filter.data = DataBuilder.GetDatasFor(Filter.GetType(), Filter); var sort = query.sort; sort.href = collection.href; sort.data = DataBuilder.GetDatasFor(typeof(SortingModel), new object()); var queries = new List <Query>(); if (collection.queries != null) { queries.AddRange(collection.queries); } queries.Add(query); collection.queries = queries; return(Configuration); }
public JsonCollection Build() { var temp_data = new List <Data>(); if (Collection.template.data != null) { temp_data.AddRange(Collection.template.data); } var data = DataBuilder.GetDatasFor(TemplateType, DataSource); temp_data.AddRange(data); foreach (var custom_data_builder in CustomsDataBuilder) { temp_data.Add(custom_data_builder(DataSource)); } Collection.template = new Template { data = temp_data }; return(Configuration.Build()); }