示例#1
0
            public CallbackForwarder(
				MamaMsg sender, 
				MamaMsgFieldIterator callback,
				object closure)
            {
                this.mSender = sender;
                this.mCallback = callback;
                this.mClosure = closure;
            }
示例#2
0
        /// <summary>
        /// Invoke the specified callback for each field in the message.
        /// </summary>
        /// <param name="iterator"></param>
        /// <param name="dictionary"></param>
        /// <param name="closure"></param>
        public void iterateFields(
			MamaMsgFieldIterator iterator,
			MamaDictionary  dictionary,
			object closure)
        {
            #if MAMA_WRAPPERS_CHECK_ARGUMENTS
            if (iterator == null)
            {
                throw new ArgumentNullException("iterator");
            }
            #endif // MAMA_WRAPPERS_CHECK_ARGUMENTS
            EnsurePeerCreated();

            IntPtr dictHandle = dictionary != null ? dictionary.NativeHandle : IntPtr.Zero;
            if (forwarder == null)
            {
                forwarder = new CallbackForwarder(this, iterator, closure);
                callback =
                    new CallbackForwarder.MamaMessageIteratorDelegate(forwarder.OnField);
                GC.SuppressFinalize(forwarder);
                GC.SuppressFinalize(callback);
            }
            else
            {
                forwarder.mCallback = iterator;
                forwarder.mClosure = closure;
            }
            int code = NativeMethods.mamaMsg_iterateFields(nativeHandle, callback, dictHandle, nativeHandle);
            CheckResultCode(code);

            GC.KeepAlive(iterator);
            GC.KeepAlive(dictionary);
        }