C# delegate method to string

Hey got a problem that I would like to know if there is a solution for. I have a delegate method that I plug a number of functions into. I want to convert the function I plugged in the delegate to a string so I can send the method over a network connection and invoke that method on the other side.
IE:
public delegate void DamageFunctions(float damage);
public DamageFunctions damageFunctionMethod;

could be:
public void Damage1(float damage);
public void Damage2(float damage);
public void Damage3(float damage);
public void Damage4(float damage);

I want to know the name of DamageX that is in damageFunctionMethod, and I want to use System.Reflection.MethodInfo to Invoke it. Is this possible or will I have to find another way to handle this?

I’m not entirely sure on where exactly you want to get the method name.

I know once you have the delegate assigned to “damageFunctionMethod”, you don’t need to use reflection to invoke it like any normal method:

damageFunctionMethod = new DamageFunctions(Damage3);
damageFunctionMethod(1.0f); //invokes Damage3

If you still want the method name, if you have the delegate you can call:
damageFunctionMethod.Method.Name

1 Like

Yep thats exactly what I needed, Thanks. For some reason it doesn’t show up in the monodev code insight for me.

I got them from Visual Studio’s intellisense. :stuck_out_tongue: