Coalesce nulls rather than null test where applicable. (#1150)

This commit is contained in:
Jon Hanna
2017-01-08 15:36:31 +13:00
committed by James Newton-King
parent 2061a8bb9a
commit f4c17aedb2
12 changed files with 33 additions and 34 deletions
@@ -649,7 +649,7 @@ namespace Newtonsoft.Json.Utilities
private static object EnsureTypeAssignable(object value, Type initialType, Type targetType)
{
Type valueType = (value != null) ? value.GetType() : null;
Type valueType = value?.GetType();
if (value != null)
{
@@ -672,7 +672,7 @@ namespace Newtonsoft.Json.Utilities
}
}
throw new ArgumentException("Could not cast or convert from {0} to {1}.".FormatWith(CultureInfo.InvariantCulture, (initialType != null) ? initialType.ToString() : "{null}", targetType));
throw new ArgumentException("Could not cast or convert from {0} to {1}.".FormatWith(CultureInfo.InvariantCulture, initialType?.ToString() ?? "{null}", targetType));
}
#if !(DOTNET || PORTABLE40 || PORTABLE)
@@ -142,7 +142,7 @@ namespace Newtonsoft.Json.Utilities
public static Type GetObjectType(object v)
{
return (v != null) ? v.GetType() : null;
return v?.GetType();
}
public static string GetTypeName(Type t, TypeNameAssemblyFormatHandling assemblyFormat, ISerializationBinder binder)
@@ -735,7 +735,7 @@ namespace Newtonsoft.Json.Utilities
{
T[] attributes = GetAttributes<T>(attributeProvider, inherit);
return (attributes != null) ? attributes.FirstOrDefault() : null;
return attributes?.FirstOrDefault();
}
#if !(DOTNET || PORTABLE)