Wombat.MamaMsg.updateVectorPrice C# (CSharp) Method

updateVectorPrice() public method

Update an array of prices.
/// Throw if the message array is null. /// /// Throw if there are no items in the message array. ///
public updateVectorPrice ( string name, ushort fid, MamaPrice 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 MamaPrice /// The array of messages to add. ///
return void
        public void updateVectorPrice(
            string name,
            ushort fid,
            MamaPrice[] val)
        {
            // Check that the arguments are valid
            if (val == null)
            {
                throw new ArgumentNullException("val");
            }

            // Check the array length
            int numberPrices = val.Length;
            if (numberPrices < 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(numberPrices * IntPtr.Size);
            try
            {
                // Create a new array to hold all of the native handles
                IntPtr[] nativeHandleArray = new IntPtr[numberPrices];

                // Copy the prices over
                for (int nextItem = 0; nextItem < numberPrices; nextItem++)
                {
                    nativeHandleArray[nextItem] = val[nextItem].NativeHandle;
                }

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

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

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