Created Writing Command-Methods page.

master
Craig Oates 7 years ago
parent
commit
bcc5790f8c
  1. 61
      Writing-Command-Methods.md

61
Writing-Command-Methods.md

@ -0,0 +1,61 @@
Before continuing, I would like to stress a "command-method" is just a regular C# method. The reason I have concocted this term is to help separate certain methods from others. The most notable **methods** are the ones which mimic the **commands** the end-user will enter at run-time -- hence **command-method** Another way to think of them is like a controller in MVC based websites.
When it comes to writing command-methods, there is a structure each one must follow. You must label each command-method as ```public``` and ```static``` and you must make sure it returns a ```string```. As long as you adhere to this structure when you write you command-methods, you can do whatever you want in them. With that said, I would like to point out how loose the "must return a string" rule is. First of all, feel free to output information to the console at any time. Console.Waterworks does not rob you of that ability. If you need to output something to the console before the method has finished executing, then go for it. On top of that, Console.Waterworks can handle empty strings if that is what you want to return. Of course, this will feel like you are using Console.Waterworks wrong. But, if this is what your method requires then do it. Console.Waterworks is an aid and nothing more.
The reason command-methods need to return a string is due to a default behaviour. Console.Waterworks wants to handle as much of the "plumbing code" as possible. This is so you can get on with solving the actual problem you are wanting to solve.
**Command-methods can only be used in ```ConsoleCommands.cs```.**
Here is an example of how your ```Main``` method and ```ConsoleCommands``` class should look.
```cs
using Console.Waterworks;
namespace CW_Console
{
class Program
{
static void Main(string[] args)
{
CW_Liaison liaison = new CW_Liaison();
liaison.Run("CW_Console", true);
// That is it. You are done here.
// Head over to ConsoleCommands.cs to begin adding features...
}
}
}
```
## ConsoleCommands.cs
```cs
using Console.Waterworks;
using Console.Waterworks.Attributes;
using System;
namespace CW_Console
{
public class ConsoleCommands
{
public static string CommandMethod1()
{
// Your code goes in here...
return "CW_Console is working.";
}
public static string CommandMethod2(string name)
{
// Your code goes in here...
return $"Hello, {name}.";
}
void DoSomething()
{
// This is not a command-method
var x = 56 + 24;
}
}
}
```
(Image: show command-methods mirroring run-time commands)
Loading…
Cancel
Save