Last active
January 16, 2023 23:45
-
-
Save YarekTyshchenko/8d5760966fc1b5d56c20 to your computer and use it in GitHub Desktop.
Collection of Space Engineers C# Scripts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Dispatch { | |
| Action<string> log = delegate(string s) {}; | |
| Dictionary<string, Action> methods = new Dictionary<string, Action>(); | |
| public void addHandler(string method, Action action) { | |
| methods.Add(method, action); | |
| } | |
| public void dispatch(string argument) { | |
| if (! methods.Contains(argument)) { | |
| log("Argument '"+argument+"' doesn't exist in collection"); | |
| return; | |
| } | |
| Action action = methods[argument]; | |
| action(); | |
| } | |
| public void setLogger(Action<string> logger) { | |
| this.log = logger; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void Main(string arg) { | |
| Dispatch d = new Dispatch(); | |
| // Optional: Define a log delegate for convenience | |
| d.setLogger(delegate(string s) { | |
| Echo("Log: "+s); | |
| }); | |
| d.addHandler("foo", delegate() { | |
| Echo("Custom Foo Action"); | |
| }); | |
| d.dispatch(arg); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment