Beispiel #1
0
        private static PathKind CalculatePathKind(IList <PathSegment> segments)
        {
            PathSegment lastSegment = segments.Last();

            if (lastSegment is NavigationSegment)
            {
                if (lastSegment.IsSingle)
                {
                    return(PathKind.SingleNavigation);
                }

                return(PathKind.CollectionNavigation);
            }
            else if (lastSegment is PropertySegment)
            {
                return(PathKind.Property);
            }
            else if (lastSegment is OperationSegment)
            {
                return(PathKind.Operation);
            }
            else if (lastSegment.Kind == SegmentKind.Type)
            {
                return(PathKind.TypeCast);
            }
            else
            {
                int count = segments.Count;
                if (count == 1)
                {
                    if (lastSegment is EntitySetSegment)
                    {
                        return(PathKind.EntitySet);
                    }
                    else if (lastSegment is SingletonSegment)
                    {
                        return(PathKind.Singleton);
                    }
                    else if (lastSegment is OperationImportSegment)
                    {
                        return(PathKind.OperationImport);
                    }

                    throw new System.Exception($"Unknown path kind!");
                }
                else if (count == 2 && lastSegment is KeySegment &&
                         segments[0] is EntitySetSegment)
                {
                    return(PathKind.Entity);
                }
                else
                {
                    PathSegment pre = segments[segments.Count - 2];
                    if (pre is NavigationSegment && lastSegment is KeySegment)
                    {
                        return(PathKind.SingleNavigation);
                    }

                    throw new System.Exception($"Unknown path kind!");
                }
            }
        }