/// <summary> /// Returns the header with the specified ID if present in the /// collection or <c>null</c>. /// </summary> /// <param name="id">The <see cref="MsgHeaderID" /></param> /// <returns>The requested <see cref="MsgHeader" /> or <c>null</c>.</returns> public MsgHeader this[MsgHeaderID id] { get { for (int i = 0; i < list.Count; i++) { if (list[i].HeaderID == id) { return(list[i]); } } return(null); } }
/// <summary> /// Constructor. /// </summary> /// <param name="headerID">The header ID.</param> /// <param name="contents">The header contents.</param> public MsgHeader(MsgHeaderID headerID, byte[] contents) { if (contents == null) { throw new ArgumentNullException("contents"); } if (contents.Length > ushort.MaxValue) { throw new ArgumentException("[contents] cannot exceed 65535 bytes."); } this.HeaderID = headerID; this.Contents = contents; }
/// <summary> /// Adds or modifies a message header in the collection. /// </summary> /// <param name="headerID">The <see cref="MsgHeaderID" /></param> /// <param name="contents">The header value encoded into a byte array.</param> /// <exception cref="InvalidOperationException">Thrown if a header with this ID is already present.</exception> public void Set(MsgHeaderID headerID, byte[] contents) { Set(new MsgHeader(headerID, contents)); }