@@ -29,8 +29,7 @@ public static class ContentHelper
2929 /// <returns>The HTTP content.</returns>
3030 public static StreamContent CreateStreamContent ( Stream stream , string contentType )
3131 {
32- if ( stream == null )
33- throw new ArgumentNullException ( nameof ( stream ) ) ;
32+ ArgumentNullException . ThrowIfNull ( stream ) ;
3433 if ( string . IsNullOrEmpty ( contentType ) )
3534 throw new ArgumentNullException ( nameof ( contentType ) ) ;
3635
@@ -72,8 +71,7 @@ public static StreamContent CreatePlainStreamContent(Stream stream)
7271 /// <returns>The HTTP content.</returns>
7372 public static StringContent CreateStringContent ( string value , string contentType , Encoding encoding = null )
7473 {
75- if ( value == null )
76- throw new ArgumentNullException ( nameof ( value ) ) ;
74+ ArgumentNullException . ThrowIfNull ( value ) ;
7775 if ( string . IsNullOrEmpty ( contentType ) )
7876 throw new ArgumentNullException ( nameof ( contentType ) ) ;
7977
@@ -87,8 +85,7 @@ public static StringContent CreateStringContent(string value, string contentType
8785 /// <returns>The HTTP content.</returns>
8886 public static StringContent CreateJsonStringContent ( string jsonString )
8987 {
90- if ( jsonString == null )
91- throw new ArgumentNullException ( nameof ( jsonString ) ) ;
88+ ArgumentNullException . ThrowIfNull ( jsonString ) ;
9289
9390 return new StringContent ( jsonString , Encoding . UTF8 , JsonContentType ) ;
9491 }
@@ -123,8 +120,7 @@ public static StringContent CreateXmlStringContent(string xmlString)
123120 public static StringContent CreateJsonStringContent ( object jsonObject )
124121 {
125122 // The name of this method is inconsistent
126- if ( jsonObject == null )
127- throw new ArgumentNullException ( nameof ( jsonObject ) ) ;
123+ ArgumentNullException . ThrowIfNull ( jsonObject ) ;
128124
129125 var json = JsonConvert . SerializeObject ( jsonObject ) ;
130126 return new StringContent ( json , Encoding . UTF8 , JsonContentType ) ;
@@ -138,8 +134,7 @@ public static StringContent CreateJsonStringContent(object jsonObject)
138134 public static StringContent CreateXmlStringContent ( XmlDocument xmlDoc )
139135 {
140136 // The name of this method is inconsistent
141- if ( xmlDoc == null )
142- throw new ArgumentNullException ( nameof ( xmlDoc ) ) ;
137+ ArgumentNullException . ThrowIfNull ( xmlDoc ) ;
143138
144139 return new StringContent ( xmlDoc . ToString ( ) , Encoding . UTF8 , XmlContentType ) ;
145140 }
@@ -153,8 +148,7 @@ public static StringContent CreateXmlStringContent(XmlDocument xmlDoc)
153148 /// <returns>The stream content as a <see cref="string"/>.</returns>
154149 public static string ConvertStreamToString ( Stream input )
155150 {
156- if ( input == null )
157- throw new ArgumentNullException ( nameof ( input ) ) ;
151+ ArgumentNullException . ThrowIfNull ( input ) ;
158152
159153 string convertedValue = string . Empty ;
160154 using ( var sr = new StreamReader ( input ) )
@@ -172,8 +166,7 @@ public static string ConvertStreamToString(Stream input)
172166 /// <returns>The stream representation.</returns>
173167 public static Stream ConvertStringToStream ( string input )
174168 {
175- if ( input == null )
176- throw new ArgumentNullException ( nameof ( input ) ) ;
169+ ArgumentNullException . ThrowIfNull ( input ) ;
177170
178171 byte [ ] byteArray = Encoding . ASCII . GetBytes ( input ) ;
179172 return new MemoryStream ( byteArray ) ;
@@ -217,8 +210,7 @@ public static string FormatJson(string json)
217210 /// </remarks>
218211 public static string FormatXml ( Stream xmlStream )
219212 {
220- if ( xmlStream == null )
221- throw new ArgumentNullException ( nameof ( xmlStream ) ) ;
213+ ArgumentNullException . ThrowIfNull ( xmlStream ) ;
222214
223215 XmlDocument xmlDoc = new XmlDocument ( ) ;
224216 xmlDoc . Load ( xmlStream ) ;
@@ -236,8 +228,7 @@ public static string FormatXml(Stream xmlStream)
236228 /// </remarks>
237229 public static string FormatXml ( string xml )
238230 {
239- if ( xml == null )
240- throw new ArgumentNullException ( nameof ( xml ) ) ;
231+ ArgumentNullException . ThrowIfNull ( xml ) ;
241232
242233 XmlDocument xmlDoc = new XmlDocument ( ) ;
243234 xmlDoc . LoadXml ( xml ) ;
@@ -252,8 +243,7 @@ public static string FormatXml(string xml)
252243 /// <returns>The formatted XML.</returns>
253244 private static string FormatXml ( XmlDocument xmlDoc )
254245 {
255- if ( xmlDoc == null )
256- throw new ArgumentNullException ( nameof ( xmlDoc ) ) ;
246+ ArgumentNullException . ThrowIfNull ( xmlDoc ) ;
257247
258248 XmlDsigC14NTransform xmlTransform = new XmlDsigC14NTransform ( ) ;
259249 xmlTransform . LoadInput ( xmlDoc ) ;
0 commit comments