Ejemplo n.º 1
0
        /// <summary>
        /// Matcheses the identifier.
        /// </summary>
        /// <param name="otherIdentifier">
        /// The other identifier.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        public virtual bool MatchesIdentifier(IIdentifier otherIdentifier)
        {
            if (otherIdentifier is MultipleIdentifier)
            {
                return(otherIdentifier.MatchesIdentifier(this));
            }

            var directMatch = $"{otherIdentifier}" == $"{this}";

            if (directMatch)
            {
                return(true);
            }

            var otherDescription = otherIdentifier?.ToString();
            var myDescription    = this.ToString();

            if (this.ToString() == "*" || otherIdentifier?.ToString() == "*")
            {
                // Super Joker
                return(true);
            }

            if (otherIdentifier?.HasWildcardSuffix == true && this.HasWildcardSuffix)
            {
                otherDescription = otherDescription.Substring(otherDescription.Length - 2);
                myDescription    = myDescription.Substring(myDescription.Length - 2);
                return(myDescription.StartsWith(otherDescription) || otherDescription.StartsWith(myDescription));
            }

            if (otherIdentifier?.HasWildcardSuffix == true)
            {
                otherDescription = otherDescription.Substring(otherDescription.Length - 2);
                return(this.ToString().StartsWith(otherDescription));
            }

            if (!this.HasWildcardSuffix)
            {
                return(false);
            }

            myDescription = myDescription.Substring(myDescription.Length - 2);
            return(otherDescription?.StartsWith(myDescription) == true);
        }