8using System.Collections.Generic;
9using System.Reflection;
46 name = nameOfExercise;
71 string version =
string.Empty;
72 Version? asm_version = typeof(
Program).Assembly.GetName().Version;
73 if (asm_version !=
null)
75 version = asm_version.ToString();
87 "{0} (v{1}) by Stephen P. Lepisto\n" +
88 "usage: {0} [--help][-?][options] [exercise_name][[ exercise_name][...]]\n" +
90 "Runs through a series of exercises showing off design patterns. If no exercise_name\n" +
91 "is given, then run through all exercises.\n" +
95 " This help text.\n" +
97 " Show just the version number of this application.\n" +
101 string appName = System.IO.Path.GetFileNameWithoutExtension(AppDomain.CurrentDomain.FriendlyName);
104 Console.WriteLine(
"\nExercises available:");
107 Console.WriteLine(
" {0}", exercise.
name);
131 bool optionsValid =
true;
133 options.exercise_names =
new List<string>();
137 foreach (
string argument
in args)
139 string arg = argument;
140 if (
string.Compare(arg,
"--help") == 0 ||
141 string.Compare(arg,
"-?") == 0 ||
142 string.Compare(arg,
"/?") == 0)
145 optionsValid =
false;
148 else if (
string.Compare(arg,
"--version") == 0)
151 optionsValid =
false;
154 options.exercise_names.Add(arg);
197 String.Compare(option_name, exercise.
name,
true) == 0) != -1)
213 static void Main(
string[] args)
Example of using the Adapter Pattern in C#.
void Run()
Executes the example for the Adapter Pattern in C#.
Example of using the Bridge Pattern in C#.
void Run()
Executes the example for the Bridge Pattern in C#.
Example of using the Command Pattern in C#.
void Run()
Executes the example for the Command Pattern in C#.
Example of using the Composite Pattern in C#.
void Run()
Executes the example for the Composite Pattern in C#.
Example of using the Decorator Pattern in C#.
void Run()
Executes the example for the Decorator Pattern in C#.
Enables the virtual terminal processing mode on the current Windows Console. When the program ends,...
Example of using the Facade Pattern in C#.
void Run()
Executes the example for the Facade Pattern in C#.
Example of using the Flyweight Pattern in C#.
void Run()
Executes the example for the Flyweight Pattern in C#.
Example of using the HandlerChain Pattern or Chain of Responsibility pattern in C#.
void Run()
Executes the example for the HandlerChain Pattern in C#.
Example of using the Interpreter Pattern in C#.
void Run()
Executes the example for the Interpreter Pattern in C#.
Example of using the Iterator Pattern in C#.
void Run()
Executes the example for the Iterator Pattern in C#.
Example of using the Memento Pattern in C#.
void Run()
Executes the example for the Memento Pattern in C#.
Example of using the Null Object Pattern in C#.
void Run()
Executes the example for the Null Object Pattern in C#.
Example of using the Observer Pattern in C#.
void Run()
Executes the example for the Observer Pattern in C#.
Contains all the top-level Design Pattern Examples.
static void Main(string[] args)
Main entry point into this example program.
string GetVersion()
Helper method to get the version of this assembly.
bool ParseOptions(string[] args, Exercise[] exercises, ref Options options)
Helper method to parse the given options and store the results in the given Options structure....
void Run(string[] args)
Run the specified examples.
void Help(Exercise[] exercises)
Helper method to show usage information for this program.
void ShowVersion()
Helper method to show just the version of the application.
Example of using the Proxy Pattern in C#.
void Run()
Executes the example for the Proxy Pattern in C#.
Example of using the State Pattern in C#.
void Run()
Executes the example for the State Pattern in C#.
Example of using the Strategy Pattern in C#.
void Run()
Executes the example for the Strategy Pattern in C#.
Example of using the Visitor Pattern in C#.
void Run()
Executes the example for the Visitor Pattern in C#.
The namespace containing all Design Pattern Examples implemented in C#.
void(* Action)(void)
Alias for a function pointer, using C# as inspiration for the name.
Represents a single exercise or example for a design pattern.
Action exercise_to_run
Method to call to run the exercise.
string name
Name of the exercise.
Exercise(string nameOfExercise, Action exercise)
Constructor.
Represents the command line options provided to the program, if any.
List< string > exercise_names
List of exercise names to run. If this list is empty, run all exercises.