Is there a better way to determine the underlying type of an object even when the current value of the object is null?
The following code doesn't work when someObject is indeed of type string but currently holding a null
value.
public void doWork(object someObject)
{
var objAsString = someObject as string;
if (objAsString != null)
{
// do work, return
// work involves string specific logging/manupulation
}
var objAsByteArr = someObject as byte[];
if (objAsByteArr != null)
{
// do work, return
// work involves byte specific logging/manupulation
}
throw new Exception("Unknown type encountered");
}