/// <summary> /// Initializes a new instance of the <see cref="ODataPath" /> class. /// </summary> /// <param name="segments">The path segments for the path.</param> public ODataPath(IEnumerable <Semantic.ODataPathSegment> segments) { if (segments == null) { throw Error.ArgumentNull("segments"); } var oDataPathSegments = segments as IList <Semantic.ODataPathSegment> ?? segments.ToList(); _edmType = oDataPathSegments.Any() ? oDataPathSegments.Last().EdmType : null; _segments = new ReadOnlyCollection <Semantic.ODataPathSegment>(oDataPathSegments); ODataPathSegmentHandler handler = new ODataPathSegmentHandler(); foreach (var segment in oDataPathSegments) { UnresolvedPathSegment pathSegment = segment as UnresolvedPathSegment; if (pathSegment != null) { handler.Handle(pathSegment); } else { segment.HandleWith(handler); } } _navigationSource = handler.NavigationSource; PathTemplate = handler.PathTemplate; _pathLiteral = handler.PathLiteral; }
/// <summary> /// Get the string representation of <see cref="ODataPath"/> mainly translate Context Url path. /// </summary> /// <param name="path">Path to compute the set for.</param> /// <returns>The string representation of the Context Url path.</returns> public static string GetPathString(this ODataPath path) { if (path == null) { throw Error.ArgumentNull(nameof(path)); } ODataPathSegmentHandler handler = new ODataPathSegmentHandler(); foreach (var segment in path) { segment.HandleWith(handler); } return(handler.PathLiteral); }