Wombat.MamaMsg.updateVectorMsg C# (CSharp) Method

updateVectorMsg() public method

Update an array of nativeHandle objects.
/// Throw if the message array is null. /// /// Throw if there are no items in the message array. ///
public updateVectorMsg ( string name, ushort fid, MamaMsg val ) : void
name string /// The field name, can be null or blank if the field Id is supplied. ///
fid ushort /// The field id, can be 0 if the name is specified and field names are turned on. ///
val MamaMsg /// The array of messages to add. ///
return void
        public void updateVectorMsg(
            string name,
            ushort fid,
            MamaMsg[] val)
        {
            // Check that the arguments are valid
            if (val == null)
            {
                throw new ArgumentNullException("val");
            }

            // Check the array length
            int numberMessages = val.Length;
            if (numberMessages < 1)
            {
                throw new ArgumentOutOfRangeException("val");
            }

            // Verify that the native message has been created
            EnsurePeerCreated();

            // Allocate memory on the global native heap to pass the messages to the native layer
            IntPtr globalHeapMemory = Marshal.AllocHGlobal(numberMessages * IntPtr.Size);
            try
            {
                // Create a new array to hold all of the native handles
                IntPtr[] nativeHandleArray = new IntPtr[numberMessages];

                // Copy the native handles over
                for (int nextItem = 0; nextItem < numberMessages; nextItem++)
                {
                    nativeHandleArray[nextItem] = val[nextItem].nativeHandle;
                }

                // Copy this to the global heap
                Marshal.Copy(nativeHandleArray, 0, globalHeapMemory, numberMessages);

                // Call the native function
                int code = NativeMethods.mamaMsg_updateVectorMsg(nativeHandle, name, fid, globalHeapMemory, numberMessages);
                CheckResultCode(code);
            }

            finally
            {
                // Free the memory on the global heap now that the function has completed
                Marshal.FreeHGlobal(globalHeapMemory);
            }
        }
MamaMsg