private D365ModelRepresentation BuildModelRepresentationLevel(PropertyInfo property) { var basicProperties = GetBasicProperties(property.PropertyType).Distinct().ToList(); var typeProperties = GetTypeProperties(property.PropertyType); var representation = new D365ModelRepresentation { RootExpandName = ExtractD365PropertyName(property), BaseProperties = basicProperties }; foreach (var typeProperty in typeProperties) { representation.ExpandProperties.Add(BuildModelRepresentationLevel(typeProperty)); } return(representation); }
private string BuildNestedLevelSelectAndExpand(D365ModelRepresentation representation) { var select = $"$select={representation.BaseProperties.ToDelimitedString(",")}"; var individualExpands = new List <string>(); foreach (var expandProp in representation.ExpandProperties) { var individualExpand = $"{expandProp.RootExpandName}({BuildNestedLevelSelectAndExpand(expandProp)})"; individualExpands.Add(individualExpand); } if (!representation.ExpandProperties.Any()) { return(select); } return($"{select};$expand={individualExpands.ToDelimitedString(",")}"); }
/// <summary> /// Extracts the model representation of a class to enable building the OData Select and Expand clauses. /// </summary> /// <returns>The <see cref="D365ModelRepresentation"/> of a D365Model</returns> public D365ModelRepresentation ExtractModelRepresentation() { var basicProperties = GetBasicProperties(_type).Distinct().ToList(); var levelOneTypeProperties = GetTypeProperties(_type); var modelRepresentation = new D365ModelRepresentation { RootExpandName = string.Empty, BaseProperties = basicProperties }; foreach (var levelOneTypeProp in levelOneTypeProperties) { modelRepresentation.ExpandProperties.Add(BuildModelRepresentationLevel(levelOneTypeProp)); } return(modelRepresentation); }