I'm currently doing an internship where I am learning C# from the ground up. My mentor has given me an exercise to demonstrate dynamic invocation. However, since I am completely new to this language, I have no idea how to implement it. I have also found there aren't that many resources that explain it very well.
This is just for a learning ramp up so I have currently been fooling around with basic functions that I can call. I have seen that this is the way to call any function you want / multiple functions at once at runtime.
public void Invoke(string typeName, string functionName)
{
Type type = Type.GetType(typeName);
dynamic c = Activator.CreateInstance(type);
//args contains the parameters(only string type)
type.InvokeMember(functionName, BindingFlags.InvokeMethod, null, c, args);
}
I'm calling it like this (This gives an error)
Invoke("void", "StringDemoPrint");
I honestly do not understand what this function is supposed to do or what it is supposed to look like when called and executed correctly. I am completely lost as to what it means.
Aucun commentaire:
Enregistrer un commentaire