Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ public static class SecureNewtonsoftDeserialization
/// <exception cref="JsonSerializationException">Thrown if the <paramref name="json"/> cannot be deserialized.</exception>
public static T DeserializeObject<T>(string json)
{
if (string.IsNullOrWhiteSpace(json))
if (json is null)
{
throw new ArgumentException($"'{nameof(json)}' cannot be null or whitespace.", nameof(json));
throw new ArgumentException($"'{nameof(json)}' cannot be null.", nameof(json));
}

JsonSerializerSettings settings = new JsonSerializerSettings
Expand All @@ -51,9 +51,9 @@ public static T DeserializeObject<T>(string json)
/// <exception cref="JsonSerializationException">Thrown if the <paramref name="json"/> cannot be deserialized.</exception>
public static T DeserializeObject<T>(string json, JsonSerializerSettings settings)
{
if (string.IsNullOrWhiteSpace(json))
if (json is null)
{
throw new ArgumentException($"'{nameof(json)}' cannot be null or whitespace.", nameof(json));
throw new ArgumentException($"'{nameof(json)}' cannot be null.", nameof(json));
}

if (settings is null)
Expand All @@ -63,7 +63,7 @@ public static T DeserializeObject<T>(string json, JsonSerializerSettings setting

if (settings.TypeNameHandling != TypeNameHandling.None)
{
throw new InsecureSerializationSettingsException($"Setting the Typenamehandling to {settings.TypeNameHandling} may result in insecure deserialization.");
throw new InsecureSerializationSettingsException($"Setting the TypeNameHandling to {settings.TypeNameHandling} may result in insecure deserialization.");
}

settings.SerializationBinder = null;
Expand All @@ -89,9 +89,9 @@ public static T DeserializeObject<T>(string json, JsonSerializerSettings setting
/// <exception cref="JsonSerializationException">Thrown if the <paramref name="json"/> cannot be deserialized.</exception>
public static T DeserializeObject<T>(string json, IEnumerable<Type> knownTypes)
{
if (string.IsNullOrWhiteSpace(json))
if (json is null)
{
throw new ArgumentException($"'{nameof(json)}' cannot be null or whitespace.", nameof(json));
throw new ArgumentException($"'{nameof(json)}' cannot be null.", nameof(json));
}

if (knownTypes is null || !knownTypes.Any())
Expand Down Expand Up @@ -127,9 +127,9 @@ public static T DeserializeObject<T>(string json, IEnumerable<Type> knownTypes)
/// <exception cref="JsonSerializationException">Thrown if the <paramref name="json"/> cannot be deserialized.</exception>
public static T DeserializeObject<T>(string json, IEnumerable<Type> knownTypes, JsonSerializerSettings settings)
{
if (string.IsNullOrWhiteSpace(json))
if (json is null)
{
throw new ArgumentException($"'{nameof(json)}' cannot be null or whitespace.", nameof(json));
throw new ArgumentException($"'{nameof(json)}' cannot be null.", nameof(json));
}

if (knownTypes is null || !knownTypes.Any())
Expand All @@ -148,4 +148,4 @@ public static T DeserializeObject<T>(string json, IEnumerable<Type> knownTypes,
return JsonConvert.DeserializeObject<T>(json, settings);
}
}
}
}