Skip to content

Commit a1f2be1

Browse files
author
henrikn
committed
Minor code clean up in cookie related classes.
1 parent 8907402 commit a1f2be1

File tree

2 files changed

+12
-17
lines changed

2 files changed

+12
-17
lines changed

src/System.Net.Http.Formatting/Headers/CookieHeaderValue.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Linq;
77
using System.Net.Http.Formatting;
88
using System.Text;
9+
using System.Web.Http;
910

1011
namespace System.Net.Http.Headers
1112
{
@@ -48,7 +49,7 @@ private CookieHeaderValue(CookieHeaderValue source)
4849
{
4950
if (source == null)
5051
{
51-
throw new ArgumentNullException("source");
52+
throw Error.ArgumentNull("source");
5253
}
5354

5455
Expires = source.Expires;

src/System.Net.Http.Formatting/Headers/CookieState.cs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
using System.Collections.Specialized;
22
using System.Diagnostics.Contracts;
33
using System.Net.Http.Formatting.Internal;
4+
using System.Web.Http;
45

56
namespace System.Net.Http.Headers
67
{
78
public class CookieState : ICloneable
89
{
910
private string _name;
10-
private NameValueCollection _values;
11+
private NameValueCollection _values = HttpValueCollection.Create();
1112

1213
public CookieState(string name)
1314
: this(name, String.Empty)
@@ -30,7 +31,7 @@ public CookieState(string name, NameValueCollection values)
3031

3132
if (values == null)
3233
{
33-
throw new ArgumentNullException("values");
34+
throw Error.ArgumentNull("values");
3435
}
3536
Values.Add(values);
3637
}
@@ -57,8 +58,8 @@ public string Name
5758
}
5859

5960
/// <summary>
60-
/// If the cookie data is a simple string value then set or retrieve it using the <see cref="M:Value"/> property.
61-
/// If the cookie data is structured then use the <see cref="M:Values"/> property.
61+
/// If the cookie data is a simple string value then set or retrieve it using the <see cref="Value"/> property.
62+
/// If the cookie data is structured then use the <see cref="Values"/> property.
6263
/// </summary>
6364
public string Value
6465
{
@@ -82,19 +83,12 @@ public string Value
8283
}
8384

8485
/// <summary>
85-
/// If the cookie data is structured then use the <see cref="M:Values"/> property for setting and getting individual values.
86-
/// If the cookie data is a simple string value then set or retrieve it using the <see cref="M:Value"/> property.
86+
/// If the cookie data is structured then use the <see cref="Values"/> property for setting and getting individual values.
87+
/// If the cookie data is a simple string value then set or retrieve it using the <see cref="Value"/> property.
8788
/// </summary>
8889
public NameValueCollection Values
8990
{
90-
get
91-
{
92-
if (_values == null)
93-
{
94-
_values = HttpValueCollection.Create();
95-
}
96-
return _values;
97-
}
91+
get { return _values; }
9892
}
9993

10094
public string this[string name]
@@ -117,7 +111,7 @@ private static void CheckNameFormat(string name, string parameterName)
117111
{
118112
if (!FormattingUtilities.ValidateHeaderToken(name))
119113
{
120-
throw new ArgumentException(Properties.Resources.CookieInvalidName, parameterName);
114+
throw Error.Argument(parameterName, Properties.Resources.CookieInvalidName);
121115
}
122116
}
123117

@@ -126,7 +120,7 @@ private static void CheckValueFormat(string value, string parameterName)
126120
// Empty string is a valid cookie value
127121
if (value == null)
128122
{
129-
throw new ArgumentNullException(parameterName);
123+
throw Error.ArgumentNull(parameterName);
130124
}
131125
}
132126
}

0 commit comments

Comments
 (0)