Beispiel #1
0
        /// <summary>
        /// Replace one word with another
        /// </summary>
        /// <param name="existing">Word to be removed.</param>
        /// <param name="replacement">Replacement word to use instead.</param>
        /// <returns>A new vocabulary set with the specified replacement.</returns>
        public VocabularySet Replace(VocabularyWord existing, VocabularyWord replacement)
        {
            if (existing == null)
            {
                throw new ArgumentNullException(nameof(existing));
            }

            if (replacement == null)
            {
                throw new ArgumentNullException(nameof(replacement));
            }

            if (!Words.Contains(existing))
            {
                throw new ArgumentException(
                          $"A word with spelling {existing.Spelling} does not exist in this set.",
                          nameof(existing));
            }

            if (existing.Equals(replacement))
            {
                return(this);
            }

            var words = _words.Remove(existing)
                        .Add(replacement);

            return(new VocabularySet(this, words: words));
        }
        public VocabularyBrowserScreen WithSelection(VocabularyWord selection)
        {
            if (Equals(Selection, selection ?? throw new ArgumentNullException(nameof(selection))))
            {
                return(this);
            }

            return(new VocabularyBrowserScreen(
                       this,
                       selection: selection));
        }
Beispiel #3
0
        /// <summary>
        /// Remove a word from this set
        /// </summary>
        /// <param name="word">The word to remove from the set.</param>
        /// <returns>A new vocabulary set without this word.</returns>
        public VocabularySet Remove(VocabularyWord word)
        {
            if (word == null)
            {
                throw new ArgumentNullException(nameof(word));
            }

            if (!Words.Contains(word))
            {
                throw new ArgumentException(
                          $"The word with spelling {word.Spelling} does not exist in this set.",
                          nameof(word));
            }

            var words = _words.Remove(word);

            return(new VocabularySet(this, words: words));
        }
Beispiel #4
0
        /// <summary>
        /// Add a new word into this set
        /// </summary>
        /// <param name="word">The word to add into the set.</param>
        /// <returns>A new vocabulary set that includes this word.</returns>
        public VocabularySet Add(VocabularyWord word)
        {
            if (word == null)
            {
                throw new ArgumentNullException(nameof(word));
            }

            if (_words.Contains(word))
            {
                return(this);
            }

            if (_words.Any(w => w.HasSpelling(word.Spelling)))
            {
                throw new ArgumentException(
                          $"A word with spelling {word.Spelling} already exists in this set.",
                          nameof(word));
            }

            var words = _words.Add(word);

            return(new VocabularySet(this, words: words));
        }
 public static ModifyVocabularyWordScreen ForExistingWord(
     VocabularyWord word)
 => new ModifyVocabularyWordScreen(word);