Exemple #1
0
      private void _parse() {
         if (PathString.IsEmpty()) {
            BplRuntimeException.Throw("Path string is empty");
         }

         var parts = PathString.Split(@"\.");
         _segments = new PathSegment[parts.Length];
         for (int i = 0, j = 0; i < parts.Length; i++) {
            try {
               var part = parts[i];
               var name = part;
               var k1 = part.IndexOf("[");
               var k2 = part.IndexOf("]");
               
               if (k1 < 0 && k2 < 0) {
                  _segments[i] = new SingleItemSegment(name);
               } else {
                  if (k1 <= 0 || k1 >= k2) {
                     j += k1;  throw new Exception();
                  }
                  if (k2 != part.Length - 1) {
                     j += k2; throw new Exception();
                  }
                  name = part.Before(k1);
                  if (k1 == k2 - 1) {
                     if (i == parts.Length - 1) {
                        j += k1; throw new Exception("A cursor expression [] cannot appear at the end of the property path.");
                     }
                     _segments[i] = new CurrentItemSegment(name);
                  } else {
                     var qualifier = part.Between(k1 + 1, k2 - 1);
                     if (qualifier == "*") {
                        if (i < parts.Length - 1) {
                           j += k1; throw new Exception("A collection expression [*] can only appear at the end of the property path.");
                        }
                        _segments[i] = new CollectionSegment(name);
                     } else {
                        int index;
                        if (Int32.TryParse(qualifier, out index) && index >= 0) {
                           _segments[i] = new IndexedItemSegment(name, index);
                        } else {
                           j += k1; throw new Exception("Invalid index [{0}].".Substitute(qualifier));
                        }
                     }
                  }
               }

               if (!BplLanguage.IsLazyLoading && !BplLanguage.PropertyNames.Contains(name)) {
                  throw new Exception("'{0}' is an invalid or unknown property name.".Substitute(name));
               }
               j += part.Length;
            } catch (Exception e) {
               BplRuntimeException.Throw("Error in path string '{0}', near position {1}.".Substitute(PathString, j), e);
            }
         }
      }
Exemple #2
0
 public ValueTask <int> GetTotalCount(
     [Parent] CollectionSegment segment,
     CancellationToken cancellationToken) =>
 segment.GetTotalCountAsync(cancellationToken);