public IJsonMappingBuilder QueryWithNesting(string propertyName, string query, string idColumn, Action <IJsonMappingBuilder> config) { if (propertyName == null) { throw new ArgumentNullException("propertyName cant be null"); } if (query == null) { throw new ArgumentNullException("query cant be null"); } if (idColumn == null) { throw new ArgumentNullException("idColumn cant be null"); } if (config == null) { throw new ArgumentNullException("config cant be null"); } var builder = new JsonMappingBuilder(this); var mappedQuery = new MappedQueryWithNestedResults(idColumn, query); builder.Result = mappedQuery; Result.MappedPropertyList.Add(new MappedProperty(propertyName, mappedQuery)); config(builder); return(this); }
/// <summary> /// Creates a mapping configuration with a query with nested results (array) as root /// This is the point to start. /// </summary> /// <param name="query"></param> /// <param name="idColumn"></param> /// <param name="config"></param> /// <returns></returns> public static IJsonMappingBuilder RootQueryWithNesting(string query, string idColumn, Action <IJsonMappingBuilder> config) { var q = new JsonMappingBuilder(null).QueryWithNesting("", query, idColumn, config); var result = new JsonMappingBuilder(null); result.Result = q.Result.MappedPropertyList.First().MappedQueryWithNestedResults; return(result); }
/// <summary> /// Creates a mapping configuration with a query (array) as root /// This is the point to start. /// </summary> /// <param name="query"></param> /// <param name="config"></param> /// <returns></returns> public static IJsonMappingBuilder RootQuery(string query, Action <IJsonMappingBuilder> config) { var q = new JsonMappingBuilder(null).Query("", query, config); var result = new JsonMappingBuilder(null); result.Result = q.Result.MappedPropertyList.First().MappedQuery; return(result); }
public IJsonMappingBuilder Object(string propertyName, Action <IJsonMappingBuilder> config) { if (propertyName == null) { throw new ArgumentNullException("propertyName cant be null"); } if (config == null) { throw new ArgumentNullException("config cant be null"); } var builder = new JsonMappingBuilder(this); Result.MappedPropertyList.Add(new MappedProperty(propertyName, builder.Result)); config(builder); return(this); }
private void AssertParentMappingHasType <TMappingType>(JsonMappingBuilder start, string property, string methodName) where TMappingType : MappedObject { JsonMappingBuilder current = start; bool found = false; while (current != null) { if (current.Result is TMappingType) { found = true; break; } current = current.parent; } if (!found) { throw new InvalidOperationException(string.Format("{0} with property name [{1}] is not allowed at this location. Parent of type [{2}] is missing.", methodName, property, typeof(TMappingType).Name)); } }
public IJsonMappingBuilder NestedResults(string propertyName, string idColumn, Action <IJsonMappingBuilder> config) { if (propertyName == null) { throw new ArgumentNullException("propertyName cant be null"); } if (idColumn == null) { throw new ArgumentNullException("idColumn cant be null"); } if (config == null) { throw new ArgumentNullException("config cant be null"); } AssertParentMappingHasType <MappedQueryWithNestedResults>(this, propertyName, "NestedResults"); var builder = new JsonMappingBuilder(this); var mappedNestedResults = new MappedNestedResults(idColumn); builder.Result = mappedNestedResults; Result.MappedPropertyList.Add(new MappedProperty(propertyName, mappedNestedResults)); config(builder); return(this); }
private JsonMappingBuilder(JsonMappingBuilder parent) { this.parent = parent; Result = new MappedObject(); }