From 33684e9fde302cbf1346a2c10a5488d61223f25d Mon Sep 17 00:00:00 2001 From: sta Date: Sun, 14 Jun 2015 17:20:30 +0900 Subject: [PATCH] Refactored a few for WebHeaderCollection.cs --- websocket-sharp/Net/WebHeaderCollection.cs | 157 +++++++++++---------- 1 file changed, 80 insertions(+), 77 deletions(-) diff --git a/websocket-sharp/Net/WebHeaderCollection.cs b/websocket-sharp/Net/WebHeaderCollection.cs index 69bf4c8b..650fe57b 100644 --- a/websocket-sharp/Net/WebHeaderCollection.cs +++ b/websocket-sharp/Net/WebHeaderCollection.cs @@ -61,7 +61,7 @@ namespace WebSocketSharp.Net #region Private Fields private static readonly Dictionary _headers; - private bool _internallyCreated; + private bool _internallyUsed; private HttpHeaderType _state; #endregion @@ -451,10 +451,10 @@ namespace WebSocketSharp.Net #region Internal Constructors - internal WebHeaderCollection (bool internallyCreated) + internal WebHeaderCollection (HttpHeaderType state, bool internallyUsed) { - _internallyCreated = internallyCreated; - _state = HttpHeaderType.Unspecified; + _state = state; + _internallyUsed = internallyUsed; } #endregion @@ -484,7 +484,7 @@ namespace WebSocketSharp.Net throw new ArgumentNullException ("serializationInfo"); try { - _internallyCreated = serializationInfo.GetBoolean ("InternallyCreated"); + _internallyUsed = serializationInfo.GetBoolean ("InternallyUsed"); _state = (HttpHeaderType) serializationInfo.GetInt32 ("State"); var cnt = serializationInfo.GetInt32 ("Count"); @@ -508,7 +508,16 @@ namespace WebSocketSharp.Net /// public WebHeaderCollection () { - _state = HttpHeaderType.Unspecified; + } + + #endregion + + #region Internal Properties + + internal HttpHeaderType State { + get { + return _state; + } } #endregion @@ -546,8 +555,8 @@ namespace WebSocketSharp.Net /// A that represents the value of the request . /// /// - /// One of the enum values, represents the request header - /// to get or set. + /// One of the enum values, represents + /// the request header to get or set. /// /// /// @@ -564,8 +573,8 @@ namespace WebSocketSharp.Net /// The length of is greater than 65,535 characters. /// /// - /// The current instance doesn't allow the request - /// . + /// The current instance doesn't allow + /// the request . /// public string this[HttpRequestHeader header] { get { @@ -584,8 +593,8 @@ namespace WebSocketSharp.Net /// A that represents the value of the response . /// /// - /// One of the enum values, represents the response header - /// to get or set. + /// One of the enum values, represents + /// the response header to get or set. /// /// /// @@ -602,8 +611,8 @@ namespace WebSocketSharp.Net /// The length of is greater than 65,535 characters. /// /// - /// The current instance doesn't allow the response - /// . + /// The current instance doesn't allow + /// the response . /// public string this[HttpResponseHeader header] { get { @@ -619,8 +628,8 @@ namespace WebSocketSharp.Net /// Gets a collection of header names in the collection. /// /// - /// A that contains all header names - /// in the collection. + /// A that contains + /// all header names in the collection. /// public override NameObjectCollectionBase.KeysCollection Keys { get { @@ -653,11 +662,11 @@ namespace WebSocketSharp.Net private static int checkColonSeparated (string header) { - var i = header.IndexOf (':'); - if (i == -1) + var idx = header.IndexOf (':'); + if (idx == -1) throw new ArgumentException ("No colon could be found.", "header"); - return i; + return idx; } private static HttpHeaderType checkHeaderType (string name) @@ -686,7 +695,7 @@ namespace WebSocketSharp.Net private void checkRestricted (string name) { - if (!_internallyCreated && isRestricted (name, true)) + if (!_internallyUsed && isRestricted (name, true)) throw new ArgumentException ("This header must be modified with the appropiate property."); } @@ -722,9 +731,7 @@ namespace WebSocketSharp.Net private static string convert (string key) { HttpHeaderInfo info; - return _headers.TryGetValue (key, out info) - ? info.Name - : String.Empty; + return _headers.TryGetValue (key, out info) ? info.Name : String.Empty; } private void doWithCheckingState ( @@ -854,8 +861,8 @@ namespace WebSocketSharp.Net #region Protected Methods /// - /// Adds a header to the collection without checking whether the header is on the restricted - /// header list. + /// Adds a header to the collection without checking if the header is on + /// the restricted header list. /// /// /// A that represents the name of the header to add. @@ -922,7 +929,7 @@ namespace WebSocketSharp.Net /// public void Add (string header) { - if (header.IsNullOrEmpty ()) + if (header == null || header.Length == 0) throw new ArgumentNullException ("header"); var pos = checkColonSeparated (header); @@ -930,12 +937,12 @@ namespace WebSocketSharp.Net } /// - /// Adds the specified request with the specified - /// to the collection. + /// Adds the specified request with + /// the specified to the collection. /// /// - /// One of the enum values, represents the request header - /// to add. + /// One of the enum values, represents + /// the request header to add. /// /// /// A that represents the value of the header to add. @@ -955,8 +962,8 @@ namespace WebSocketSharp.Net /// The length of is greater than 65,535 characters. /// /// - /// The current instance doesn't allow the request - /// . + /// The current instance doesn't allow + /// the request . /// public void Add (HttpRequestHeader header, string value) { @@ -964,12 +971,12 @@ namespace WebSocketSharp.Net } /// - /// Adds the specified response with the specified - /// to the collection. + /// Adds the specified response with + /// the specified to the collection. /// /// - /// One of the enum values, represents the response header - /// to add. + /// One of the enum values, represents + /// the response header to add. /// /// /// A that represents the value of the header to add. @@ -989,8 +996,8 @@ namespace WebSocketSharp.Net /// The length of is greater than 65,535 characters. /// /// - /// The current instance doesn't allow the response - /// . + /// The current instance doesn't allow + /// the response . /// public void Add (HttpResponseHeader header, string value) { @@ -998,8 +1005,8 @@ namespace WebSocketSharp.Net } /// - /// Adds a header with the specified and - /// to the collection. + /// Adds a header with the specified and + /// to the collection. /// /// /// A that represents the name of the header to add. @@ -1025,8 +1032,8 @@ namespace WebSocketSharp.Net /// The length of is greater than 65,535 characters. /// /// - /// The current instance doesn't allow the header - /// . + /// The current instance doesn't allow + /// the header . /// public override void Add (string name, string value) { @@ -1063,8 +1070,8 @@ namespace WebSocketSharp.Net /// Get the value of the header with the specified in the collection. /// /// - /// A that receives the value of the header if found; otherwise, - /// . + /// A that receives the value of the header if found; + /// otherwise, . /// /// /// A that represents the name of the header to find. @@ -1103,12 +1110,12 @@ namespace WebSocketSharp.Net } /// - /// Gets an array of header values stored in the specified position - /// of the collection. + /// Gets an array of header values stored in the specified position of + /// the collection. /// /// - /// An array of that receives the header values if found; otherwise, - /// . + /// An array of that receives the header values if found; + /// otherwise, . /// /// /// An that represents the zero-based index of the header to find. @@ -1119,17 +1126,15 @@ namespace WebSocketSharp.Net public override string[] GetValues (int index) { var vals = base.GetValues (index); - return vals != null && vals.Length > 0 - ? vals - : null; + return vals != null && vals.Length > 0 ? vals : null; } /// /// Gets an array of header values stored in the specified . /// /// - /// An array of that receives the header values if found; otherwise, - /// . + /// An array of that receives the header values if found; + /// otherwise, . /// /// /// A that represents the name of the header to find. @@ -1137,9 +1142,7 @@ namespace WebSocketSharp.Net public override string[] GetValues (string header) { var vals = base.GetValues (header); - return vals != null && vals.Length > 0 - ? vals - : null; + return vals != null && vals.Length > 0 ? vals : null; } /// @@ -1163,7 +1166,7 @@ namespace WebSocketSharp.Net if (serializationInfo == null) throw new ArgumentNullException ("serializationInfo"); - serializationInfo.AddValue ("InternallyCreated", _internallyCreated); + serializationInfo.AddValue ("InternallyUsed", _internallyUsed); serializationInfo.AddValue ("State", (int) _state); var cnt = Count; @@ -1233,15 +1236,15 @@ namespace WebSocketSharp.Net /// Removes the specified request from the collection. /// /// - /// One of the enum values, represents the request header - /// to remove. + /// One of the enum values, represents + /// the request header to remove. /// /// /// is a restricted header. /// /// - /// The current instance doesn't allow the request - /// . + /// The current instance doesn't allow + /// the request . /// public void Remove (HttpRequestHeader header) { @@ -1252,15 +1255,15 @@ namespace WebSocketSharp.Net /// Removes the specified response from the collection. /// /// - /// One of the enum values, represents the response header - /// to remove. + /// One of the enum values, represents + /// the response header to remove. /// /// /// is a restricted header. /// /// - /// The current instance doesn't allow the response - /// . + /// The current instance doesn't allow + /// the response . /// public void Remove (HttpResponseHeader header) { @@ -1288,8 +1291,8 @@ namespace WebSocketSharp.Net /// /// /// - /// The current instance doesn't allow the header - /// . + /// The current instance doesn't allow + /// the header . /// public override void Remove (string name) { @@ -1300,8 +1303,8 @@ namespace WebSocketSharp.Net /// Sets the specified request to the specified value. /// /// - /// One of the enum values, represents the request header - /// to set. + /// One of the enum values, represents + /// the request header to set. /// /// /// A that represents the value of the request header to set. @@ -1321,8 +1324,8 @@ namespace WebSocketSharp.Net /// The length of is greater than 65,535 characters. /// /// - /// The current instance doesn't allow the request - /// . + /// The current instance doesn't allow + /// the request . /// public void Set (HttpRequestHeader header, string value) { @@ -1333,8 +1336,8 @@ namespace WebSocketSharp.Net /// Sets the specified response to the specified value. /// /// - /// One of the enum values, represents the response header - /// to set. + /// One of the enum values, represents + /// the response header to set. /// /// /// A that represents the value of the response header to set. @@ -1354,8 +1357,8 @@ namespace WebSocketSharp.Net /// The length of is greater than 65,535 characters. /// /// - /// The current instance doesn't allow the response - /// . + /// The current instance doesn't allow + /// the response . /// public void Set (HttpResponseHeader header, string value) { @@ -1389,8 +1392,8 @@ namespace WebSocketSharp.Net /// The length of is greater than 65,535 characters. /// /// - /// The current instance doesn't allow the header - /// . + /// The current instance doesn't allow + /// the header . /// public override void Set (string name, string value) {