Beispiel #1
0
        /// <summary>
        /// Determines if a binding path is valid
        /// </summary>
        /// <param name="path">The binding path</param>
        /// <returns>True, if the path is valid; otherwise false</returns>
        /// <remarks>
        /// The rules for a valid binding path are as follows:
        ///
        /// - The trimmed path must not contain whitespace
        /// - The first character must be either a letter or dollar sign
        /// - The path segments can end with [*] indexers
        /// - Subsequent characters may be letters, dots, square brackets or numbers
        /// - Sequential dots are not allowed (e.g. "..")
        /// </remarks>
        public static bool IsValidPath
        (
            string path
        )
        {
            // Rule: the path must not contain spaces
            if (String.IsNullOrWhiteSpace(path) || path.Contains(" "))
            {
                return(false);
            }

            // Rule: must start with letter or dollar sign
            var firstChar = path.First();

            var isValidChar =
                (
                    Char.IsLetter(firstChar) || firstChar == '$'
                );

            if (false == isValidChar)
            {
                return(false);
            }

            // Rule: sequential dots are not allowed
            if (path.Contains(".."))
            {
                return(false);
            }

            path = PathInfo.TrimPath(path);

            // Rule: the path segments can end with an indexer
            var segments = path.Split('.');

            foreach (var segment in segments)
            {
                var isValid = PathSegmentInfo.IsValidSegment
                              (
                    segment
                              );

                if (false == isValid)
                {
                    return(false);
                }
            }

            return(true);
        }
Beispiel #2
0
        /// <summary>
        /// Populates the segments details
        /// </summary>
        /// <param name="index">The segment index</param>
        /// <param name="signature">The segment signature</param>
        private void PopulateSegmentDetails
        (
            int index,
            string signature
        )
        {
            var isValid = PathSegmentInfo.IsValidSegment
                          (
                signature
                          );

            if (false == isValid)
            {
                throw new ArgumentException
                      (
                          "The path segment '{0}' is invalid.".With
                          (
                              signature
                          )
                      );
            }

            var indexerInfo = new IndexerInfo
                              (
                signature
                              );

            this.Index       = index;
            this.Signature   = signature;
            this.Name        = indexerInfo.PathWithoutIndexer;
            this.IndexerInfo = indexerInfo;

            this.IsModelPointer = TemplateContext.IsModelReference
                                  (
                indexerInfo.PathWithoutIndexer
                                  );
        }