Ejemplo n.º 1
0
        /// <summary>
        /// Gets or sets the <see cref="BroValue"/> for the specified field <paramref name="name"/>.
        /// </summary>
        /// <returns>
        /// The <see cref="BroField"/> with the specified field name, or <c>null</c> if there was an issue retrieving value.
        /// </returns>
        /// <param name="name">Then name of the <see cref="BroField"/> to get or set.</param>
        /// <exception cref="ObjectDisposedException">Cannot get or set <see cref="BroField"/>, Bro record is disposed.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="name"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentNullException">Cannot set a <c>null</c> <see cref="BroField"/>.</exception>
        /// <exception cref="InvalidOperationException">Failed to update <see cref="BroField"/> with <paramref name="name"/>.</exception>
        public BroValue this[string name]
        {
            get
            {
                if (m_recordPtr.IsInvalid())
                {
                    throw new ObjectDisposedException("Cannot get field, Bro record is disposed.");
                }

                if ((object)name == null)
                {
                    throw new ArgumentNullException("name");
                }

                BroType type     = BroType.Unknown;
                IntPtr  valuePtr = BroApi.bro_record_get_named_val(m_recordPtr, name, ref type);

                return(new BroField(BroValue.CreateFromPtr(valuePtr, type), name));
            }
            set
            {
                if (m_recordPtr.IsInvalid())
                {
                    throw new ObjectDisposedException("Cannot set field, Bro record is disposed.");
                }

                if ((object)name == null)
                {
                    throw new ArgumentNullException("name");
                }

                if ((object)value == null)
                {
                    throw new ArgumentNullException("value");
                }

                if (value.ExecuteWithFixedPtr(ptr => BroApi.bro_record_set_named_val(m_recordPtr, name, value.Type, value.TypeName, ptr) == 0))
                {
                    throw new InvalidOperationException(string.Format("Failed to update field with name \"{0}\".", name));
                }
            }
        }