vendredi 29 janvier 2016

Programatically fetching Singleton instances that implement a common interface

I'm working with some legacy ASP.NET MVC code that has a number of fairly detailed XML configuration files. Each file is loaded into an object representation defined as a Singleton class at runtime.

Rather than having to refer to each singleton specifically by class type I'd like a way of obtaining each of them programatically and then being able to access properties and methods common to them all based on an interface which they must all implement.

So for example, these singletons all have a string instance property called "Filename" that is the name of the config file they represent. I'd therefore like to automatically generate a list of these filenames without manually having to refer to each singleton to obtain the property and therefore I need to programatically fetch all singleton instances implementing the interface that specifies the Filename property and then fetch that property value by casting to that interface.

Is this possible?





Aucun commentaire:

Enregistrer un commentaire