jeudi 6 septembre 2018

Does the conversion between interfaces involve reflection?

I have this empty interface IProvider and another interface called ICountryProvider that inherits from IProvider. I'm storing different kinds of "providers" inside a dictionary which is declared like this.

Dictionary<string, IProvider> dic;

Now, when I want to get a specific "provider" implementation let it be ICountryProvider, I do the following:

var countryProvider = (ICountryProvider)dic["country"];

Now, I'm concerned about the performance because this will be executed on each request to my API. So, I want to ask, is this a casting operation and does it involve any reflection-related operation?


Also, I have side questions, does the runtime cache the result of such "conversion" if it's called a conversion? Is there any performance difference betwee "converting" from object to ICountryProvier and from IProvider to ICountryProvider?



Aucun commentaire:

Enregistrer un commentaire