public override void GetObjectData( SerializationInfo serializationInfo, StreamingContext streamingContext) { if (serializationInfo.IsNull ()) throw new ArgumentNullException ("serializationInfo"); serializationInfo.AddValue ("InternallyCreated", internallyCreated); serializationInfo.AddValue ("State", (int) state); int count = Count; serializationInfo.AddValue ("Count", count); count.Times (i => { serializationInfo.AddValue (i.ToString (), GetKey (i)); serializationInfo.AddValue ((count + i).ToString (), Get (i)); }); }
/// <summary> /// Initializes a new instance of the <see cref="WebHeaderCollection"/> class /// with the specified <see cref="SerializationInfo"/> and <see cref="StreamingContext"/>. /// </summary> /// <param name="serializationInfo"> /// A <see cref="SerializationInfo"/> that contains the data to need to serialize the <see cref="WebHeaderCollection"/> object. /// </param> /// <param name="streamingContext"> /// A <see cref="StreamingContext"/> that contains the source of the serialized stream associated with the new <see cref="WebHeaderCollection"/>. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="serializationInfo"/> is <see langword="null"/>. /// </exception> /// <exception cref="ArgumentException"> /// An element with the specified name is not found in <paramref name="serializationInfo"/>. /// </exception> protected WebHeaderCollection( SerializationInfo serializationInfo, StreamingContext streamingContext) { if (serializationInfo.IsNull ()) throw new ArgumentNullException ("serializationInfo"); try { internallyCreated = serializationInfo.GetBoolean ("InternallyCreated"); state = (HttpHeaderType) serializationInfo.GetInt32 ("State"); int count = serializationInfo.GetInt32 ("Count"); count.Times (i => { base.Add ( serializationInfo.GetString (i.ToString ()), serializationInfo.GetString ((count + i).ToString ())); }); } catch (SerializationException ex) { throw new ArgumentException (ex.Message, "serializationInfo", ex); } }