Is it possible to compare two objects without knowing their boxed types at compile time?
For instance, if I have a object{long}
and object{int}
, is there a way to know if the boxed values are equal?
My method retrieves two generic object
s, and there's no way to know what their inner types are at compile time. Right now, the comparison is made by the following code:
_keyProperties[x].GetValue(entity, null).Equals(keyValues[x])
where, say, _keyProperties[x].GetValue(entity, null)
is a object{long}
and keyValues[x]
is a object{int}
(but they can be inverted as well).
I need this because I am building a mock repository for my unit tests, and I have started by including a generic repository implementation as described here. This implementation compares two generic fake-DB keys in its Find
method.