Click here to Skip to main content
15,795,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I find a class in the data section of my API by its name, using Assemblies, and I convert it to a type, where I can add values to its properties.

Now I need to convert it process it in a CRUD type API - which won't take the type (it uses a generic TEntity).

This is how I get it - how do I convert it?

public Type importClass { get; set; }
protected virtual IList<Assembly> Assemblies
                return new List<Assembly>()

public CSVMatch(string className)
            _className = className;
            foreach (var assembly in Assemblies) {
                var classes = assembly.ExportedTypes.Where(c => c.Name == className);
                if (classes != null)
                    importClass = class[0];


What I have tried:

I've tried a generic handler which didn't accept the type
Updated 6-Oct-21 10:47am
Gerry Schmitz 6-Oct-21 15:23pm    

1 solution

Maybe you can use Activator.CreateInstance, see example here:
Dynamically Create Instance of a Class at Runtime in C#[^]
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900