mercredi 19 août 2020

Get all method inside a method using Reflection in C#

I have this code:

public class ClassMigration: Migration
{
   public override void RunMigration()
   {
      Utility.AddLanguage(new CultureInfo("en-PH"));
      Utility.AddLanguage(new CultureInfo("en-US"));
      Utility.ServerSetting("MAIN_LANGUAGE", "en-US"));
   }
}

I'm using reflection to get the the void method RunMigration() through I'm having a hard time to get what is inside the RunMigration() method.

What I am trying to achieve is to get all methods inside RunMigration and get all CultureInfo and ServerSetting parameter.

I already have this code:

private static IEnumerable<CultureInfo> GetLanguages(Type type)
{
   var languages = new List<CultureInfo>();
   if(type == null || !type.Name.Contains("Class")) return languages;
   foreach(var method in type.Getmethods())
   {
      // how to get those methods that is declared inside the void method.
   }
}

How do I achieve this?





Aucun commentaire:

Enregistrer un commentaire