/// <summary>
        /// Translate a TypeSegment
        /// </summary>
        /// <param name="segment">the segment to Translate</param>
        /// <returns>Translated WebApi path segment</returns>
        public override IEnumerable <ODataPathSegment> Translate(Semantic.TypeSegment segment)
        {
            IEdmType elementType = segment.EdmType;

            if (segment.EdmType.TypeKind == EdmTypeKind.Collection)
            {
                elementType = ((IEdmCollectionType)segment.EdmType).ElementType.Definition;
            }

            if (elementType.TypeKind == EdmTypeKind.Entity)
            {
                yield return(new CastPathSegment((IEdmEntityType)elementType));
            }
            else if (elementType.TypeKind == EdmTypeKind.Complex)
            {
                yield return(new ComplexCastPathSegment((IEdmComplexType)elementType));
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Get sub select and expand clause by property name, if the propertyname is in form of TypeCast/Property, the typeSegment would also be returned.
        /// </summary>
        /// <param name="clause">The root clause.</param>
        /// <param name="propertyName">The property name to navigate to.</param>
        /// <param name="subSelectExpand">The sub select and expand clause under sub property.</param>
        /// <param name="typeSegment">Type cast segment, if exists.</param>
        internal static void GetSubSelectExpandClause(this SelectExpandClause clause, string propertyName, out SelectExpandClause subSelectExpand, out TypeSegment typeSegment)
        {
            subSelectExpand = null;
            typeSegment     = null;

            ExpandedNavigationSelectItem selectedItem = clause
                                                        .SelectedItems
                                                        .OfType <ExpandedNavigationSelectItem>()
                                                        .FirstOrDefault(
                m => m.PathToNavigationProperty.LastSegment != null &&
                m.PathToNavigationProperty.LastSegment.TranslateWith(PathSegmentToStringTranslator.Instance) == propertyName);

            if (selectedItem != null)
            {
                subSelectExpand = selectedItem.SelectAndExpand;
                typeSegment     = selectedItem.PathToNavigationProperty.FirstSegment as TypeSegment;
            }
        }
 /// <summary>
 /// Determine the NavigationSource of a TypeSegment
 /// </summary>
 /// <param name="segment">The TypeSegment to look in.</param>
 /// <returns>The IEdmNavigationSource of this TypeSegment</returns>
 /// <exception cref="System.ArgumentNullException">Throws if the input segment is null.</exception>
 public override IEdmNavigationSource Translate(TypeSegment segment)
 {
     ExceptionUtils.CheckArgumentNotNull(segment, "segment");
     return(segment.NavigationSource);
 }