This tip shows the simulation of the
IS operator working in C#. It isn't an exact replica but instead if
IS operator wasn't supported, how else we could produce it.
bool IsOperatorCheck(object arg1, object arg2)
if (arg1.GetType().IsValueType && arg2.GetType().IsValueType)
result = (arg1.GetType() == arg2.GetType());
result = (arg1.GetType().Equals(arg2.GetType()));
My guru Jon Skeet says here http://blogs.msdn.com/b/csharpfaq/archive/2004/03/29/when-should-i-use-and-when-should-i-use-equals.aspx[^] when to use
Hence in the above code, I have used
== for valuetypes and if either of them isn't a valuetype, I am using
I have tested with valuetypes as well as custom reference type inputs.
P.S: I hope it helps in some way, and I am open for suggestions/learning. Thanks.