A colleague asked me an interesting question today - is the C# keyword/operator \"is\" considered reflection?
object tmp = \"a string\";
if(tmp is String)
{
The is
operator essentially determines if a cast is possible, but instead of throwing an exception when the cast is impossible it returns false
. If you consider casting reflection then this is also reflection.
EDIT:
After some research I have discovered that a cast is performed in IL på the castclass
instruction while the is
operator maps to the isinst
instruction. FxCop has a rule that warns you if you are doing unecessary casts by first using the isinst
and then the castclass
instruction. Even though the operations are efficient they still have a performance cost.