dimanche 28 août 2016

get field of constructor by reflection in C#

I have a string array like this:

namespace DynamicCore
    {
        public class DynamicCode
        {
            public string ProcessName { get; set; }
            public DynamicCode()
            {
                List<Variable> variableList = new List<Variable>();
                Variable Variable = new Variable();

                Variable.ID = "Variable_26545789";
                Variable.Name = "var1";
                variableList_Process_1.Add(Variable);

                Variable = new Variable();

                Variable.ID = "Variable_vdvd3679";
                Variable.Name = "var2";    

                variableList_Process_1.Add(Variable);
            }
        }
    }

I compiled it using CompileAssemblyFromSource like this (GetCode gets string array) and store class in Memory:

CompilerResults results = provider.CompileAssemblyFromSource(parameters, GetCode());

I need to get variableList and show Variable.Name items in a listbox. I tested GetFields and GetProperty but none was not working properly.

It would be very helpful if someone could explain solution for this problem.

Thanks.





Aucun commentaire:

Enregistrer un commentaire