Esempio n. 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HierarchicalSelector"/> class.
 /// </summary>
 /// <param name="path">The path.</param>
 /// <param name="context">The context.</param>
 public HierarchicalSelector(
     string path,
     HierarchicalPath context)
     : base(path, context)
 {
     ParseSelectors();
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="HierarchicalPathKeyValue&lt;TValue&gt;"/> class.
        /// </summary>
        /// <param name="hierarchicalPath">The hierarchical path.</param>
        /// <param name="value">The value.</param>
        public HierarchicalPathKeyValue(
            HierarchicalPath hierarchicalPath,
            TValue value)
        {
            if (hierarchicalPath == null)
            {
                throw new ArgumentNullException("hierarchicalPath");
            }

            HierarchicalPath = hierarchicalPath;
            Value            = value;
        }
 /// <summary>
 /// Compares the current object with another object of the same type.
 /// </summary>
 /// <param name="other">An object to compare with this object.</param>
 /// <returns>
 /// A 32-bit signed integer that indicates the relative order of the objects being compared. The return value has the following meanings:
 /// Value
 /// Meaning
 /// Less than zero
 /// This object is less than the <paramref name="other"/> parameter.
 /// Zero
 /// This object is equal to <paramref name="other"/>.
 /// Greater than zero
 /// This object is greater than <paramref name="other"/>.
 /// </returns>
 public int CompareTo(IHierarchicalPathContainer other)
 {
     return(HierarchicalPath.CompareTo(other.HierarchicalPath));
 }
 /// <summary>
 /// Compares the current object with another object of the same type.
 /// </summary>
 /// <param name="other">An object to compare with this object.</param>
 /// <returns>
 /// A 32-bit signed integer that indicates the relative order of the objects being compared. The return value has the following meanings:
 /// Value
 /// Meaning
 /// Less than zero
 /// This object is less than the <paramref name="other"/> parameter.
 /// Zero
 /// This object is equal to <paramref name="other"/>.
 /// Greater than zero
 /// This object is greater than <paramref name="other"/>.
 /// </returns>
 public int CompareTo(HierarchicalPath other)
 {
     return(HierarchicalPath.CompareTo(other));
 }
 /// <summary>
 /// Serves as a hash function for a particular type.
 /// </summary>
 /// <returns>
 /// A hash code for the current <see cref="T:System.Object"/>.
 /// </returns>
 /// <filterpriority>2</filterpriority>
 public override int GetHashCode()
 {
     return(HierarchicalPath.GetHashCode());
 }
Esempio n. 6
0
        /// <summary>
        /// Determines whether the specified path is match for the selector.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="startIndex">The start index.</param>
        /// <returns>
        ///     <c>true</c> if the specified path is match; otherwise, <c>false</c>.
        /// </returns>
        public bool IsMatch(
            HierarchicalPath path,
            int startIndex)
        {
            // If the selector is longer than the given path, it will never
            // match the path.
            if (Levels.Count > path.Levels.Count)
            {
                return(false);
            }

            // Go through all the elements of the selector.
            for (int selectorIndex = 0,
                 pathIndex = startIndex;
                 selectorIndex < Levels.Count;
                 selectorIndex++)
            {
                // Check to see if we have a special function for the selector's
                // level.
                object operation = operations[selectorIndex];
                string pathLevel = path.Levels[pathIndex];

                if (operation == null)
                {
                    // Just do a string comparison between the two levels.
                    if (Levels[selectorIndex] != pathLevel)
                    {
                        // It doesn't match, so return false.
                        return(false);
                    }

                    pathIndex++;
                    continue;
                }

                // If we are regular expression, then use that.
                if (operation is Regex)
                {
                    if (!((Regex)operation).IsMatch(pathLevel))
                    {
                        // It doesn't match the regular expression.
                        return(false);
                    }

                    pathIndex++;
                    continue;
                }

                // If we got this far, we are a double-star match. If this is
                // the last index in the selector, it will match everything.
                if (selectorIndex == Levels.Count - 1)
                {
                    return(true);
                }

                // Loop through the remaing elements of the path and see if
                // we can find a subtree match.
                var subSelector = (HierarchicalSelector)operation;

                for (int starIndex = pathIndex;
                     starIndex < path.Levels.Count;
                     starIndex++)
                {
                    // If this is a match, use it.
                    if (subSelector.IsMatch(path, starIndex))
                    {
                        return(true);
                    }
                }

                // We couldn't find a subtree match.
                return(false);
            }

            // If we got through the entire loop, we have a match.
            return(true);
        }
Esempio n. 7
0
 /// <summary>
 /// Determines whether the specified path is match for the selector.
 /// </summary>
 /// <param name="path">The path.</param>
 /// <returns>
 ///     <c>true</c> if the specified path is match; otherwise, <c>false</c>.
 /// </returns>
 public bool IsMatch(HierarchicalPath path)
 {
     return(IsMatch(path, 0));
 }
Esempio n. 8
0
        /// <summary>
        /// Determines whether the specified path is match for the selector.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <returns>
        ///     <c>true</c> if the specified path is match; otherwise, <c>false</c>.
        /// </returns>
        public bool IsMatch(string path)
        {
            var hierarchicalPath = new HierarchicalPath(path);

            return(IsMatch(hierarchicalPath));
        }