コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Wildcard"/> class.
        /// </summary>
        /// <param name="supported">The supported <see cref="WildcardSelection"/>.</param>
        /// <param name="multiWildcard">The .NET multi (zero or more) wildcard character (defaults to <see cref="MultiWildcardCharacter"/>).</param>
        /// <param name="singleWildcard">The .NET single wildcard character (defaults to <see cref="char.MinValue"/>).</param>
        /// <param name="charactersNotAllowed">The list of characters that are not allowed.</param>
        /// <param name="transform">The <see cref="StringTransform"/> option for the wildcard text.</param>
        /// <param name="spaceTreatment">The <see cref="WildcardSpaceTreatment"/> that defines the treatment of embedded space ' ' characters within the wildcard.</param>
        public Wildcard(WildcardSelection supported, char multiWildcard = MultiWildcardCharacter, char singleWildcard            = char.MinValue, char[]?charactersNotAllowed = null,
                        WildcardSpaceTreatment spaceTreatment           = WildcardSpaceTreatment.None, StringTransform transform = StringTransform.EmptyToNull)
        {
            if (supported == WildcardSelection.Undetermined || supported.HasFlag(WildcardSelection.InvalidCharacter))
            {
                throw new ArgumentException("A Wildcard cannot be configured with Undetermined and/or InvalidCharacter supported selection(s).", nameof(supported));
            }

            if (multiWildcard != char.MinValue && singleWildcard != char.MinValue && multiWildcard == singleWildcard)
            {
                throw new ArgumentException("A Wildcard cannot be configured with the same character for the MultiWildcard and SingleWildcard.", nameof(multiWildcard));
            }

            if (charactersNotAllowed != null && (charactersNotAllowed.Contains(multiWildcard) || charactersNotAllowed.Contains(singleWildcard)))
            {
                throw new ArgumentException("A Wildcard cannot be configured with either the MultiWildcard or SingleWildcard in the CharactersNotAllowed list.", nameof(charactersNotAllowed));
            }

            if (supported.HasFlag(WildcardSelection.MultiWildcard) && multiWildcard == char.MinValue)
            {
                throw new ArgumentException("A Wildcard that supports MultiWildcard must also define the MultiWildcard character.");
            }

            if (supported.HasFlag(WildcardSelection.SingleWildcard) && singleWildcard == char.MinValue)
            {
                throw new ArgumentException("A Wildcard that supports SingleWildcard must also define the SingleWildcard character.");
            }

            Supported            = supported;
            MultiWildcard        = multiWildcard;
            SingleWildcard       = singleWildcard;
            CharactersNotAllowed = new ReadOnlyCollection <char>(charactersNotAllowed != null ? (char[])charactersNotAllowed.Clone() : Array.Empty <char>());
            SpaceTreatment       = spaceTreatment;
            Transform            = transform;
        }
コード例 #2
0
 /// <summary>
 /// Validates the <paramref name="selection"/> against what is <see cref="Supported"/> to ensure validity.
 /// </summary>
 /// <param name="selection">The <see cref="WildcardSelection"/> to validate.</param>
 /// <returns><c>true</c> indicates that the selection is valid; otherwise, <c>false</c> for invalid.</returns>
 public bool Validate(WildcardSelection selection)
 {
     if ((selection.HasFlag(WildcardSelection.None) && !Supported.HasFlag(WildcardSelection.None)) ||
         (selection.HasFlag(WildcardSelection.Equal) && !Supported.HasFlag(WildcardSelection.Equal)) ||
         (selection.HasFlag(WildcardSelection.Single) && !Supported.HasFlag(WildcardSelection.Single)) ||
         (selection.HasFlag(WildcardSelection.StartsWith) && !Supported.HasFlag(WildcardSelection.StartsWith)) ||
         (selection.HasFlag(WildcardSelection.EndsWith) && !Supported.HasFlag(WildcardSelection.EndsWith)) ||
         (selection.HasFlag(WildcardSelection.Contains) && !Supported.HasFlag(WildcardSelection.Contains)) ||
         (selection.HasFlag(WildcardSelection.Embedded) && !Supported.HasFlag(WildcardSelection.Embedded)) ||
         (selection.HasFlag(WildcardSelection.MultiWildcard) && !Supported.HasFlag(WildcardSelection.MultiWildcard)) ||
         (selection.HasFlag(WildcardSelection.SingleWildcard) && !Supported.HasFlag(WildcardSelection.SingleWildcard)) ||
         (selection.HasFlag(WildcardSelection.AdjacentWildcards) && !Supported.HasFlag(WildcardSelection.AdjacentWildcards)) ||
         (selection.HasFlag(WildcardSelection.InvalidCharacter)))
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }
コード例 #3
0
 private void Check(WildcardSelection selection, string text, WildcardResult result)
 {
     Assert.AreEqual(selection, result.Selection);
     Assert.AreEqual(text, result.Text);
 }