0

I'm trying to get information from a variable within a method in C# MVC 5.

Example, I have methods just like this and want to get the parameters that are used in the variable "dt" in the example below.

public static JsonResult NamesDropDownListTest()
{
    var dt = MyClass.QueryStoreProcedureDataTableTest(DataWareHouse,"gpkTest.procedure_type_docs");

    return new JsonResult
    {
        Data = dt,
        JsonRequestBehavior = JsonRequestBehavior.AllowGet,
        MaxJsonLength = int.MaxValue
    };
}

I am trying through this code that I saw here in the forum:

        var asm = Assembly.Load("MyAssemblyNameProject");

    var listAsm = asm.GetTypes()
            .SelectMany(type => type.GetMethods(BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Public))
            .Where(m => !m.GetCustomAttributes(typeof(System.Runtime.CompilerServices.CompilerGeneratedAttribute), true).Any())
            .Select(x => new { Classe = x.DeclaringType.Name, Action = x.Name, ReturnType = x.ReturnType.Name, Attributes = string.Join(",", x.GetCustomAttributes().Select(a => a.GetType().Name.Replace("Attribute", ""))), Parameter = string.Join(",", x.GetParameters().Select(s => new { atributo = s.ParameterType.FullName, nome = s.Name }).ToList()), teste = string.Join(",", x.Attributes) })
            .OrderBy(x => x.Classe).ThenBy(x => x.Action).ToList();

I want to bring this information, such as method name, the action and which methods were found containing these variables I need the names of these parameters. I hope I was clear.

Thank you in advance to all.

Fernando Arce
  • 332
  • 2
  • 14

1 Answers1

1

Information about local variables and method calls are not available through reflection. You'd have to use some sort of decompiler or static analysis tool to find out where methods are actually used within your code.

D Stanley
  • 149,601
  • 11
  • 178
  • 240