V
V
V Sh.2016-07-11 13:48:13
C++ / C#
V Sh., 2016-07-11 13:48:13

How to return the name of a function that is stored in a delegate?

Good afternoon!
Tell me how to do it. Here is an example:

namespace bla_bla_bla
{
      public delegate string bonusFunction(Game game);

      public static class Bonus
     {
            public static string Kattenacho(Game game)
            {
                  return "Каттеначо";
            }
      }

      class Program
      {
             static void Main(string[] args)
             {
                      bonusFunction b = Bonus.Kattenacho;
                      Console.WriteLine(b.GetType().FullName);
             }
      }
}

Naturally, it gives me bla_bla_bla.bonusFunction. What should I write so that it issues bla_bla_bla.Bonus.Kattenacho?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
ar4ebaldello, 2016-07-11
@JuniorNoobie

bonusFunction b = Bonus.Kattenacho;
Type methodHost = b.Method.DeclaringType;
string methodName = b.Method.Name;
Console.WriteLine("{0} -> {1}", methodHost.FullName, methodName);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question