7using System.Collections.Generic;
52 source.Text = source.
Text.Replace(searchPattern, replaceText);
61 StringBuilder output =
new StringBuilder();
62 string text = source.
Text;
63 for (
int index = 0; index < text.Length; ++index)
65 output.Append(text[text.Length - 1 - index]);
67 source.Text = output.ToString();
92 Console.WriteLine(
" undoing command {0,-31}: \"{1}\"", lastCommand, text);
108 Console.WriteLine(
" command {0,-31}: \"{1}\"", command, text);
123 Console.WriteLine(
" command {0,-31}: \"{1}\"", command, text);
134 Console.WriteLine(
"Command Exercise");
142 Console.WriteLine(
" Starting text: \"{0}\"", text);
150 Console.WriteLine(
" Now perform undo until back to original");
158 Console.WriteLine(
" Final text : \"{0}\"", text);
160 Console.WriteLine(
" Done.");
Example of using the Command Pattern in C#.
void Command_Operation_Replace(Command_TextObject source, string searchPattern, string replaceText)
An operation to search and replace text in a Command_TextObject.
void Command_ApplyReplaceCommand(Command_TextObject text, string searchPattern, string replaceText)
Helper function to create a Command object that replaces text in the given Command_TextObject,...
void Command_ApplyReverseCommand(Command_TextObject text)
Helper function to create a Command object that reverses the order of the characters in the given Com...
void Command_Save_And_Execute(Command_TextObject text, Command command)
Save the given command on the undo list then execute the command on the given text object.
void Command_Operation_Reverse(Command_TextObject source)
An operation to reverse the characters in the given Command_TextObject.
void Run()
Executes the example for the Command Pattern in C#.
void Command_Undo(Command_TextObject text)
Perform an undo on the given Command_TextObject, using the commands in the "global" undo list....
Stack< Command > _commandUndoList
The list of commands applied.
Container for a string. Need to use a class that allows the text to be changed while the container (t...
void Reset()
Resets the TextObject to the starting string.
string Text
Gets or sets the text in this TextObject.
Represents an operation that can be applied to a TextObject. This class can handle two kinds of opera...
void Execute()
Execute the command on the TextObject.
The namespace containing all Design Pattern Examples implemented in C#.