예제 #1
0
        /// <summary>
        /// Determines if the segment signature is valid
        /// </summary>
        /// <param name="signature">The segment signature</param>
        /// <returns>True, if it is valid; otherwise false</returns>
        /// <remarks>
        /// The segment signature is valid if it only contains
        /// letters, numbers and optionally ends with an indexer.
        /// </remarks>
        public static bool IsValidSegment
        (
            string signature
        )
        {
            if (String.IsNullOrWhiteSpace(signature))
            {
                return(false);
            }

            if (signature == @"$")
            {
                return(true);
            }

            var indexerInfo = new IndexerInfo
                              (
                signature
                              );

            signature = indexerInfo.PathWithoutIndexer;

            var containsValidChars = signature.All
                                     (
                c => Char.IsLetter(c) ||
                Char.IsNumber(c)
                                     );

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

            return(true);
        }
예제 #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
                                  );
        }
예제 #3
0
        /// <summary>
        /// Populates the indexer details based on the binding path
        /// </summary>
        /// <param name="path">The binding path</param>
        /// <param name="signatureIndex">THe signature index</param>
        private void PopulateIndexerDetails
        (
            string path,
            int signatureIndex = 0
        )
        {
            if (path.StartsWith(@".") && path.Length > 1)
            {
                path = path.Crop(1);
            }

            var extractedSignatures = ExtractIndexerSignatures
                                      (
                path
                                      );

            if (extractedSignatures.Length == 0)
            {
                this.HasIndexer         = false;
                this.ResolvedIndex      = -1;
                this.PathWithoutIndexer = path;
                this.FullPath           = path;
            }
            else
            {
                var signature = extractedSignatures[signatureIndex];

                if (signature.Length > 2)
                {
                    signature = signature.Crop
                                (
                        1,
                        signature.Length - 2
                                );
                }

                var valueResolver = new NettleValueResolver();

                var valueType = valueResolver.ResolveType
                                (
                    signature
                                );

                switch (valueType)
                {
                case NettleValueType.Number:
                {
                    this.ResolvedIndex = Int32.Parse(signature);
                    break;
                }

                case NettleValueType.Variable:
                {
                    this.ResolvedIndex = -1;
                    break;
                }

                default:
                {
                    var message  = "The indexer '{0}' for '{1}' is invalid.";
                    var position = (path.Length - signature.Length);

                    throw new NettleParseException
                          (
                              message.With(signature, path),
                              position
                          );
                }
                }

                var indexerSequence = String.Empty;
                var trimSequence    = String.Empty;

                for (var i = 0; i < extractedSignatures.Length; i++)
                {
                    indexerSequence += extractedSignatures[i];

                    if (i > signatureIndex)
                    {
                        trimSequence += extractedSignatures[i];
                    }
                }

                this.HasIndexer       = true;
                this.IndexerValueType = valueType;
                this.IndexerSignature = signature;

                this.PathWithoutIndexer = path.Substring
                                          (
                    0,
                    path.Length - indexerSequence.Length
                                          );

                this.FullPath = path.Substring
                                (
                    0,
                    path.Length - trimSequence.Length
                                );

                if (signatureIndex < extractedSignatures.Length - 1)
                {
                    this.NextIndexer = new IndexerInfo
                                       (
                        path,
                        signatureIndex + 1
                                       );
                }
            }
        }