Ejemplo n.º 1
0
        /// <summary>
        /// Creates a new ODataPath with the specified segment added.
        /// </summary>
        /// <param name="path">The path against which the segment should be applied.</param>
        /// <param name="segment">The segment applied to the path.</param>
        /// <returns>A new ODataPath with the segment appended.</returns>
        public static ODataPath AddSegment(this ODataPath path, ODataPathSegment segment)
        {
            var newPath = new ODataPath(path);

            newPath.Add(segment);
            return(newPath);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Append 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 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>The ODataPath with key segment appended</returns>
        public static ODataPath AppendKeySegment(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);
            foreach (var segment in handler.LastPart)
            {
                newPath.Add(segment);
            }

            return(newPath);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Build a segment representing a property.
        /// </summary>
        /// <param name="path">Path to perform the computation on.</param>
        /// <param name="property">The property this segment represents.</param>
        /// <returns>>The ODataPath with property segment appended in the end.</returns>
        public static ODataPath AppendPropertySegment(this ODataPath path, IEdmStructuralProperty property)
        {
            var             newPath         = new ODataPath(path);
            PropertySegment propertySegment = new PropertySegment(property);

            newPath.Add(propertySegment);
            return(newPath);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Build a segment representing a navigation property.
        /// </summary>
        /// <param name="path">Path to perform the computation on.</param>
        /// <param name="navigationProperty">The navigation property this segment represents.</param>
        /// <param name="navigationSource">The navigation source of the entities targeted by this navigation property. This can be null.</param>
        /// <returns>The ODataPath with navigation property segment appended in the end.</returns>
        public static ODataPath AppendNavigationPropertySegment(this ODataPath path, IEdmNavigationProperty navigationProperty, IEdmNavigationSource navigationSource)
        {
            var newPath = new ODataPath(path);
            NavigationPropertySegment np = new NavigationPropertySegment(navigationProperty, navigationSource);

            newPath.Add(np);
            return(newPath);
        }
Ejemplo n.º 5
0
        /// <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);
        }