Beispiel #1
0
        public static IntPtr AddressOfHeap <T>(ref T t, OffsetType offset) where T : class
        {
            switch (offset)
            {
            case OffsetType.StringData:

                AssertType <string, T>();
                var s = t as string;
                return(AddressOfHeap(ref s) + RuntimeHelpers.OffsetToStringData);

            case OffsetType.ArrayData:

                if (!typeof(T).IsArray)
                {
                    TypeException.Throw <Array, T>();
                }

                return(AddressOfHeap(ref t) + Runtime.Runtime.OffsetToArrayData);

            case OffsetType.Fields:

                // todo: if the type is an array, should this return ArrayData,
                // todo: ...and if it's a string, should this return StringData?

                // Skip over the MethodTable*
                return(AddressOfHeap(ref t) + IntPtr.Size);

            case OffsetType.None:
                return(AddressOfHeap(ref t));

            default:
                throw new ArgumentOutOfRangeException(nameof(offset), offset, null);
            }
        }
Beispiel #2
0
        public static ArrayObject **GetArrayObject <T>(ref T t) where T : class
        {
            if (!typeof(T).IsArray)
            {
                TypeException.Throw <Array, T>();
            }

            return((ArrayObject **)Unsafe.AddressOf(ref t));
        }