/// <summary>
        /// Remove the type-cast segment in the end of ODataPath, the method does not modify current ODataPath instance,
        /// it returns a new ODataPath without ending type segment.
        /// </summary>
        /// <param name="path">Path to perform the computation on.</param>
        /// <returns>The ODataPath without type-cast in the end</returns>
        public static ODataPath TrimEndingTypeSegment(this ODataPath path)
        {
            var handler = new SplitEndingSegmentOfTypeHandler <TypeSegment>();

            path.WalkWith(handler);
            return(handler.FirstPart);
        }
        /// <summary>
        /// Remove the key segment in the end of ODataPath, the method does not modify current ODataPath instance,
        /// it returns a new ODataPath without ending type segment.
        /// If last segment is type cast, the key before type cast segment would be removed.
        /// </summary>
        /// <param name="path">Path to perform the computation on.</param>
        /// <returns>The ODataPath without key segment removed</returns>
        public static ODataPath TrimEndingKeySegment(this ODataPath path)
        {
            var typeHandler = new SplitEndingSegmentOfTypeHandler <TypeSegment>();
            var keyHandler  = new SplitEndingSegmentOfTypeHandler <KeySegment>();

            path.WalkWith(typeHandler);
            typeHandler.FirstPart.WalkWith(keyHandler);
            ODataPath newPath = keyHandler.FirstPart;

            AppendLastSegment(typeHandler, newPath);
            return(newPath);
        }
        /// <summary>
        /// Add the key segment in the ODataPath, the method does not modify current ODataPath instance,
        /// it returns a new ODataPath without ending type segment.
        /// If last segment is type cast, the key would be appended before type cast segment.
        /// </summary>
        /// <param name="path">Path to perform the computation on.</param>
        /// <param name="keys">The set of key property names and the values to be used in searching for the given item.</param>
        /// <param name="edmType">The type of the item this key returns.</param>
        /// <param name="navigationSource">The navigation source that this key is used to search.</param>
        /// <returns>A new ODataPath with key segment added</returns>
        public static ODataPath AddKeySegment(this ODataPath path, IEnumerable <KeyValuePair <string, object> > keys, IEdmEntityType edmType, IEdmNavigationSource navigationSource)
        {
            var handler = new SplitEndingSegmentOfTypeHandler <TypeSegment>();

            path.WalkWith(handler);
            KeySegment keySegment = new KeySegment(keys, edmType, navigationSource);
            ODataPath  newPath    = handler.FirstPart;

            newPath.Add(keySegment);
            AppendLastSegment(handler, newPath);

            return(newPath);
        }
        /// <summary>
        /// Remove the key segment in the end of ODataPath, the method does not modify current ODataPath instance,
        /// it returns a new ODataPath without ending type segment.
        /// If last segment is type cast, the key before type cast segment would be removed.
        /// </summary>
        /// <param name="path">Path to perform the computation on.</param>
        /// <returns>The ODataPath without key segment removed</returns>
        public static ODataPath TrimEndingKeySegment(this ODataPath path)
        {
            var typeHandler = new SplitEndingSegmentOfTypeHandler <TypeSegment>();
            var keyHandler  = new SplitEndingSegmentOfTypeHandler <KeySegment>();

            path.WalkWith(typeHandler);
            typeHandler.FirstPart.WalkWith(keyHandler);
            ODataPath newPath = keyHandler.FirstPart;

            foreach (var segment in typeHandler.LastPart)
            {
                newPath.Add(segment);
            }

            return(newPath);
        }
Exemple #5
0
        /// <summary>
        /// Translate the parameter alias, convert node, returned entity set into OData path segment.
        /// </summary>
        /// <param name="model">The EDM model</param>
        /// <param name="path">The odata path segments</param>
        /// <param name="parameterAliasNodes">The parameter alias</param>
        /// <returns>The translated odata path segments.</returns>
        public static IEnumerable <ODataPathSegment> Translate(IEdmModel model, Semantic.ODataPath path,
                                                               IDictionary <string, SingleValueNode> parameterAliasNodes)
        {
            if (model == null)
            {
                throw Error.ArgumentNull("model");
            }

            if (path == null)
            {
                throw Error.ArgumentNull("path");
            }

            var translator = new ODataPathSegmentTranslator(model, parameterAliasNodes);

            return(path.WalkWith(translator));
        }
 /// <summary>
 /// Get the string representation of <see cref="ODataPath"/>.
 /// mainly translate Query Url path.
 /// </summary>
 /// <param name="path">Path to perform the computation on.</param>
 /// <param name="urlKeyDelimiter">Mark whether key is segment</param>
 /// <returns>The string representation of the Query Url path.</returns>
 public static string ToResourcePathString(this ODataPath path, ODataUrlKeyDelimiter urlKeyDelimiter)
 {
     return(string.Concat(path.WalkWith(new PathSegmentToResourcePathTranslator(urlKeyDelimiter)).ToArray()).TrimStart('/'));
 }