mardi 20 juillet 2021

How can I create a C# IEnumerable<"ClassName"> at run time?

I'm currently creating a machine learning engine that will run certain routines that are configured in the database. I want to create a method that will handle multiple types of IEnumerable that are passed from the DB as a string. I will have already defined the class type in the project, I just want to dynamically create the IEnumerable from the string name of the class.

Updated with more info:

Below is an example of the List I want to populate using dapper (.net core).

The machine learning prediction engine requires column attributes adding to the class so it knows what to do with it. I've pretty much accepted that I won't be able to dynamically create the class, I just want to create a List<"ClassName"> dynamically to save on code. I could write a case statement for every type of List I want to create but don't really want to.

Here's the class defintion:

class PriceChange24
    {
        [LoadColumn(0)]
        public Single Volume { get; set; }
        
        [LoadColumn(1)]
        public Single PriceChange1H { get; set; }

        [LoadColumn(2)]
        public Single PriceChange24H { get; set; }

        [LoadColumn(3)]
        public Single PriceChange7D { get; set; }

        [LoadColumn(4)]
        public Single PriceChange1HAvg { get; set; }

        [LoadColumn(5)]
        public Single PriceChange24HAvg { get; set; }

        [LoadColumn(6)]
        public Single PriceChange7DAvg { get; set; }

        [LoadColumn(7)]
        public Single RSI { get; set; }

        [LoadColumn(8), ColumnName("Label")]
        public bool GreaterThan10_24 { get; set; }

        public Single Volume24H { get; set; }

        public string Symbol { get; set; }

        public Single GBPValue { get; set; }

        public DateTime LastUpdated { get; set; }

}




Aucun commentaire:

Enregistrer un commentaire