vendredi 30 juillet 2021

How to use class name dynamically using its name in c#?

I want to insert object to my repository but not explicitly.

 _repository<Car>().Add(carObject); // explicit

instead of this, I want to push the object to the corresponding class name at the run time. I can create the object in run time but can't set the class name in __repository<???>().Add(object) here.
For example: I've a string name "Car" [it might be other class name like "Person" ], then how can I do the same thing using the given code?
If you need more information I can provide. Thanks.





Aucun commentaire:

Enregistrer un commentaire