コード例 #1
0
        /// <summary>
        /// Attempts to dereference the pointer, returning the innermost pointer level as a ref type.
        /// If at any point along the way, the pointed to address is null, the method fails.
        /// </summary>
        public bool TryDereference(ref TStruct value)
        {
            TStruct *currentAddress = Address;

            if (currentAddress == (TStruct *)0)
            {
                return(false);
            }

            for (int x = 0; x < DepthLevel - 1; x++)
            {
                currentAddress = *(TStruct **)(currentAddress);
                if (currentAddress == (TStruct *)0)
                {
                    return(false);
                }
            }

            value = Create(currentAddress); // Lack of ref here is not a typo.
            return(true);
        }
コード例 #2
0
        /// <summary>
        /// Attempts to dereference the pointer, returning the innermost pointer level as a ref type.
        /// If at any point along the way, the pointed to address is null, the method fails.
        /// </summary>
        /// <returns></returns>
        public ref TStruct TryDereference(out bool success)
        {
            TStruct *currentAddress = Address;

            success = false;

            if (currentAddress == (TStruct *)0)
            {
                return(ref Create(currentAddress));
            }

            for (int x = 0; x < DepthLevel - 1; x++)
            {
                currentAddress = *(TStruct **)(currentAddress);
                if (currentAddress == (TStruct *)0)
                {
                    return(ref Create(currentAddress));
                }
            }

            success = true;
            return(ref Create(currentAddress));
        }
コード例 #3
0
        /// <summary>
        /// Attempts to dereference the pointer, returning the innermost pointer as a pointer.
        /// If at any point along the way, the pointed to address is null, the method fails.
        /// </summary>
        public bool TryDereference(out TStruct *value)
        {
            TStruct *currentAddress = Address;

            value = (TStruct *)0;

            if (currentAddress == (TStruct *)0)
            {
                return(false);
            }

            for (int x = 0; x < DepthLevel - 1; x++)
            {
                currentAddress = *(TStruct **)(currentAddress);
                if (currentAddress == (TStruct *)0)
                {
                    return(false);
                }
            }

            value = currentAddress;
            return(true);
        }
コード例 #4
0
 /// <param name="address">Address of the pointer in memory.</param>
 /// <param name="depthLevel">Depth level of the pointer/number of required dereferences to meet target address. 1 = void*, 2 = void**, 3 - void*** etc.</param>
 public RefPointer(TStruct *address, int depthLevel)
 {
     Address    = address;
     DepthLevel = depthLevel;
 }
コード例 #5
0
 /// <summary>
 /// Converts a pointer into a by reference variable.
 /// </summary>
 /// <param name="pointer">Pointer to the unmanaged structure.</param>
 /// <returns>A by reference variable for a given pointer.</returns>
 public static ref TStruct Create(TStruct *pointer) => ref Unsafe.AsRef <TStruct>(pointer);
コード例 #6
0
 /// <summary>
 /// Creates a by reference array pointer given the address of the first element of the array.
 /// </summary>
 /// <param name="structPtr">Pointer to the address of the first element of the structure array.</param>
 public RefArrayPtr(TStruct *structPtr) => Pointer = (TStruct *)structPtr;
コード例 #7
0
 /// <summary>
 /// Creates a by reference array pointer given the address of the first element of the array.
 /// </summary>
 /// <param name="structPtr">Pointer to the address of the first element of the structure array.</param>
 /// <param name="numberOfItems">Number of items in this array.</param>
 public RefFixedArrayPtr(TStruct *structPtr, int numberOfItems)
 {
     Pointer = structPtr;
     Count   = numberOfItems;
 }