this
refers to the instance the code is currently running in.
I think you are probaby adding the this.GetType() to a static method. And a static method is not linked to an instance, so that does not work.
Type thisType = this.GetType();
MethodInfo theMethod = thisType.GetMethod(TheCommandString);
theMethod.Invoke(this, userParameters);
Works like this:
this.GetType
//or
typeof(ClassName)
Gets the type, which is the class definition you can use at run time.
MethodInfo theMethod = thisType.GetMethod(TheCommandString);
tries to get method definition from type. This can then be used to call (invoke)
theMethod.Invoke(this, userParameters);
Invokes the method definition. But since the method definition does not know to which instance it belongs to, you have to pass an instance, and the parameters you wish to pass. (parameters are not required)
An example would be:
public static void Main()
{
var test = new Test();
Type thisType = test.GetType();
MethodInfo theMethod = thisType.GetMethod("Boop");
theMethod.Invoke(test , new object[0]);
}
public class Test
{
public void Boop()
{
Console.WriteLine("Boop");
}
}
Can see the code at:
https://dotnetfiddle.net/67ljft