When I am checking my cache to see if if my ValueTuple is in the cache, I use the code below. In this scenario, the value coming back is null (aka does not exist in the cache). When the code runs I get object not set to instance of an object
error on the 1st line. Is there a proper way to cast an object to a ValueTuple?
var geo = ((double, double))CacheEngine.Get(key);
if (!geo.Equals(default(ValueTuple<double, double>))) return geo;
I found that I needed to do it like this to work. You need to cast to ValueTuple<double, double>
and not (double, double).
var geo = CacheEngine.Get(key);
if (geo != null)
{
var geoTuple = (ValueTuple<double, double>)geo;
if (!geoTuple.Equals(default(ValueTuple<double, double>)))
return geoTuple;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With