/// <summary> /// Gets MetadataItem object for URI relative path under the specified EntityContainer instance /// </summary> /// <param name="container">The EntityContainer instance</param> /// <param name="pathSegment">The URI relative path</param> /// <param name="uriType">Output parameter of UriType value</param> /// <returns>The MetadataItem instance if one is found; null otherwise</returns> private static MetadataItem GetTargetType(EntityContainer container, IEnumerable <string> pathSegment, ref UriType uriType) { ODataUriItem curr = new ODataUriItem(container, UriType.URI_Container); foreach (var segment in pathSegment) { // to normalize first segment string segmentKey; string segmentCore = ResourcePathHelper.ParseSegment(segment, out segmentKey); ODataUriItem subItem = curr.GetItem(segmentCore); if (subItem == null) { uriType = UriType.URIUNKNOWN; return(null); } if (subItem.uriType == UriType.URI1 && !string.IsNullOrEmpty(segmentKey)) { subItem = new ODataUriItem(((EntitySet)subItem.Item).ElementType, UriType.URI2); } curr = subItem; } uriType = curr.uriType; return(curr.Item); }
/// <summary> /// Gets ODataUriItem instance by specified name /// </summary> /// <param name="name">name of sub item</param> /// <returns>sub-item if one is found; null otherwise</returns> public ODataUriItem GetItem(string name) { switch (this.uriType) { case UriType.URI_Container: return(GetItem((EntityContainer)this.Item, name)); case UriType.URI1: return(GetItem((EntitySet)this.Item, name)); case UriType.URI2: return(GetItem((EntityType)this.Item, name)); case UriType.URI3: ComplexType ct = (ComplexType)((EdmProperty)this.Item).TypeUsage.EdmType; return(GetItem(ct, name)); case UriType.URI4: case UriType.URI5: case UriType.URI14: if (name.Equals("$value", StringComparison.Ordinal)) { return(this); } else { return(null); } case UriType.URI6: RelationshipEndMember asso = (RelationshipEndMember)this.Item; var alias = new ODataUriItem(asso.GetEntityType(), UriType.URI2); return(alias.GetItem(name)); case UriType.URI_Link: var next = GetItem((EntityType)this.Item, name); if (next.uriType == UriType.URI6) { return(new ODataUriItem(next.Item, UriType.URI7)); } else { return(null); } default: return(null); } }
/// <summary> /// Gets collection of RelationshipEndMember as navigation targets along the navigation path from the EntityType object /// </summary> /// <param name="entityType">The EntityType instance to start with</param> /// <param name="navigation">The navigation path</param> /// <returns>Collection of navigation targets</returns> public static IEnumerable<RelationshipEndMember> GetNavigationStack(EntityType entityType, IEnumerable<string> navigation) { var result = new List<RelationshipEndMember>(); EntityType currEntityType = entityType; UriType uriType = UriType.URI2; foreach(var nav in navigation) { ODataUriItem curr = new ODataUriItem(currEntityType, uriType); var next = curr.GetItem(nav); RelationshipEndMember navRole = (RelationshipEndMember)next.Item; result.Add(navRole); currEntityType = navRole.GetEntityType(); } return result; }
/// <summary> /// Gets collection of RelationshipEndMember as navigation targets along the navigation path from the EntityType object /// </summary> /// <param name="entityType">The EntityType instance to start with</param> /// <param name="navigation">The navigation path</param> /// <returns>Collection of navigation targets</returns> public static IEnumerable <RelationshipEndMember> GetNavigationStack(EntityType entityType, IEnumerable <string> navigation) { var result = new List <RelationshipEndMember>(); EntityType currEntityType = entityType; UriType uriType = UriType.URI2; foreach (var nav in navigation) { ODataUriItem curr = new ODataUriItem(currEntityType, uriType); var next = curr.GetItem(nav); RelationshipEndMember navRole = (RelationshipEndMember)next.Item; result.Add(navRole); currEntityType = navRole.GetEntityType(); } return(result); }
/// <summary> /// Gets ODataUriItem instance by specified name /// </summary> /// <param name="name">name of sub item</param> /// <returns>sub-item if one is found; null otherwise</returns> public ODataUriItem GetItem(string name) { switch (this.uriType) { case UriType.URI_Container: return GetItem((EntityContainer)this.Item, name); case UriType.URI1: return GetItem((EntitySet)this.Item, name); case UriType.URI2: return GetItem((EntityType)this.Item, name); case UriType.URI3: ComplexType ct = (ComplexType)((EdmProperty)this.Item).TypeUsage.EdmType; return GetItem(ct, name); case UriType.URI4: case UriType.URI5: case UriType.URI14: if (name.Equals("$value", StringComparison.Ordinal)) { return this; } else { return null; } case UriType.URI6: RelationshipEndMember asso = (RelationshipEndMember)this.Item; var alias = new ODataUriItem(asso.GetEntityType(), UriType.URI2); return alias.GetItem(name); case UriType.URI_Link: var next = GetItem((EntityType)this.Item, name); if (next.uriType == UriType.URI6) { return new ODataUriItem(next.Item, UriType.URI7); } else { return null; } default: return null; } }
/// <summary> /// Gets MetadataItem object for URI relative path under the specified EntityContainer instance /// </summary> /// <param name="container">The EntityContainer instance</param> /// <param name="pathSegment">The URI relative path</param> /// <param name="uriType">Output parameter of UriType value</param> /// <returns>The MetadataItem instance if one is found; null otherwise</returns> private static MetadataItem GetTargetType(EntityContainer container, IEnumerable<string> pathSegment, ref UriType uriType) { ODataUriItem curr = new ODataUriItem(container, UriType.URI_Container); foreach (var segment in pathSegment) { // to normalize first segment string segmentKey; string segmentCore = ResourcePathHelper.ParseSegment(segment, out segmentKey); ODataUriItem subItem = curr.GetItem(segmentCore); if (subItem == null) { uriType = UriType.URIUNKNOWN; return null; } if (subItem.uriType == UriType.URI1 && !string.IsNullOrEmpty(segmentKey)) { subItem = new ODataUriItem(((EntitySet)subItem.Item).ElementType, UriType.URI2); } curr = subItem; } uriType = curr.uriType; return curr.Item; }