samedi 15 août 2015

How can I determine if an implicit cast exists in c#?

I have to types T and U, and I want to know whether an implicit cast operator is defined from From to To.

I'm aware of the existence of IsAssignableFrom and this is not what I'm looking for, as it doesn't deal with implicit casts.

A bit of googling led me to this solution, but in the own words on the author this is ugly code (it tries to cast implicitly and returns false if there's an exception, true otherwise...)

Is there a cleaner way of determining the existence of an implicit cast operator?





Aucun commentaire:

Enregistrer un commentaire