how to create a class in time of execution


I'm a novice with the reflection emitted, I found a code for the creation of a class in time of execution: dynamically-create-a-class-at-runtime

I want to make a class from reading a string vector and create a class called (for example Patient)

        MyClassBuilder MCB=new MyClassBuilder("Pacient");
        Guid id = Guid.NewGuid();
        string[] info = {id.ToString(), "Name: Felica Walker", "Title: Mz.",
                       "Age: 47", "Location: Paris", "Gender: F"};

With what I understood from the link where it is referenced, I try to get the field name and the type

var myclass = MCB.CreateObject(new string[] { "PacientID","Name", "Title", "Age", "Location", "Gender" }, new Type[] { typeof(string), typeof(string), typeof(string), typeof(int), typeof(string), typeof(string) });
        Type TP = myclass.GetType();

        using (StreamWriter writer = new StreamWriter("Pacient.cs"))

            foreach (PropertyInfo PI in TP.GetProperties())


the base class I have it in the following way:

    public class DinClass
    public string fieldName { get; set; }
    public string fieldType { get; set; }

As you can see I could only get the properties, but all the other components of a class ...

asked by ger 03.12.2018 в 23:26

0 answers