Example #1
0
        public bool BeginsWith(NameWithPrefix beginning)
        {
            // diff. prefixes?
            if (HasPrefix != beginning.HasPrefix || !string.Equals(prefix, beginning.prefix, StringComparison.OrdinalIgnoreCase))
                return false;

            // beginning longer than current value?
            if (beginning.names.Length > names.Length)
                return false;

            for (int i = 0; i < beginning.names.Length; i++)
            {
                if (!string.Equals(names[i], beginning.names[i], StringComparison.OrdinalIgnoreCase))
                    return false;
            }

            return true;
        }
Example #2
0
        public NameWithPrefix RemoveBeginning(NameWithPrefix beginning)
        {
            if (!BeginsWith(beginning))
                throw new InvalidOperationException(string.Format("Can't remove beginning \"{0}\" from name \"{1}\" because it isn't starts with same prefix and names.", beginning, this));

            if (beginning.names.Length == names.Length)
                throw new InvalidOperationException(string.Format("Can't remove all names from \"{0}\".", this));

            string[] newNames = new string[this.names.Length - beginning.names.Length];
            Array.Copy(this.names, beginning.names.Length, newNames, 0, newNames.Length);
            return new NameWithPrefix(null, newNames);
        }
Example #3
0
        public static NameWithPrefix Combine(NameWithPrefix p1, NameWithPrefix p2)
        {
            if (p2.HasPrefix)
                throw new ArgumentException("Second name can't have prefix.", "p2");

            string[] names = new string[p1.names.Length + p2.names.Length];
            Array.Copy(p1.names, names, p1.names.Length);
            Array.Copy(p2.names, 0, names, p1.names.Length, p2.names.Length);
            return new NameWithPrefix(p1.prefix, names);
        }