So I want to exit the execution of a method or function by calling for another method. I have so far only found problems with else and nothing like I need.
Example as follows..
public static void SomeMethod() {
// some code
ExitMethod();
// the next line of code will never be executed
Console.WriteLine("Test");
}
private static void ExitMethod() {
// if possible the execution of the Method above will be stopped here
}
The ExitMethod would work like a return statement, only that because it is a method I can more easily add an if or other conditions to it. If I were to use the ExitMethod often in my assembly I could easily refactor the conditions under which execution of the calling Method would be stopped.
This can for example be used in an obviously insecure attempt of securing a dll, so that it requires a serial key and only if the correct one is given it will enable some static bool that then is checked everytime a function is called from the dll.
Thanks in advance :)
EDIT: By using another method that can be called for the cancellation task I want to avoid something like:
public static void SomeMethod() {
if (ExitMethod) return;
}
The goal is to only be required to call the ExitMethod Method which takes care of things.