public static ClrObject GetInnerObject(ulong pointer, ClrType type)
{
ulong fieldAddress;
ClrType actualType = type;
if (type.IsObjectReference)
{
type.Heap.ReadPointer(pointer, out fieldAddress);
if (!type.IsSealed && fieldAddress != 0)
actualType = type.Heap.GetObjectType(fieldAddress);
}
else if (type.IsPrimitive)
{
// Unfortunately, ClrType.GetValue for primitives assumes that the value is boxed,
// we decrement PointerSize because it will be added when calling ClrType.GetValue.
// ClrMD should be updated in a future version to include ClrType.GetValue(int interior).
fieldAddress = pointer - (ulong)type.Heap.PointerSize;
}
else if (type.IsValueClass)
{
fieldAddress = pointer;
}
else
{
throw new NotSupportedException(string.Format("Object type not supported '{0}'", type.Name));
}
return new ClrObject(fieldAddress, actualType, !type.IsObjectReference);
}