Update compiler package and fix nullable warnings (#2163)

This commit is contained in:
James Newton-King
2019-09-15 21:24:24 +12:00
committed by GitHub
parent 7cc65dab82
commit 6b9f467e81
34 changed files with 184 additions and 151 deletions
+1 -1
View File
@@ -6,7 +6,7 @@
<MicrosoftCodeAnalysisFxCopAnalyzersPackageVersion>2.9.2</MicrosoftCodeAnalysisFxCopAnalyzersPackageVersion>
<MicrosoftCSharpPackageVersion>4.3.0</MicrosoftCSharpPackageVersion>
<MicrosoftSourceLinkGitHubPackageVersion>1.0.0-beta2-19367-01</MicrosoftSourceLinkGitHubPackageVersion>
<MicrosoftNetCompilersToolsetPackageVersion>3.3.0-beta1-final</MicrosoftNetCompilersToolsetPackageVersion>
<MicrosoftNetCompilersToolsetPackageVersion>3.3.1-beta3-final</MicrosoftNetCompilersToolsetPackageVersion>
<MicrosoftNETTestSdkPackageVersion>15.7.2</MicrosoftNETTestSdkPackageVersion>
<MoqPackageVersion>4.8.1</MoqPackageVersion>
<NunitPackageVersion>3.11.0</NunitPackageVersion>
@@ -71,7 +71,7 @@ namespace Newtonsoft.Json.Converters
if (value.GetType().FullName == BinaryTypeName)
{
EnsureReflectionObject(value.GetType());
Debug.Assert(_reflectionObject != null);
MiscellaneousUtils.Assert(_reflectionObject != null);
return (byte[])_reflectionObject.GetValue(value, BinaryToArrayName)!;
}
@@ -142,7 +142,7 @@ namespace Newtonsoft.Json.Converters
if (t.FullName == BinaryTypeName)
{
EnsureReflectionObject(t);
Debug.Assert(_reflectionObject != null);
MiscellaneousUtils.Assert(_reflectionObject != null);
return _reflectionObject.Creator!(data);
}
@@ -60,7 +60,7 @@ namespace Newtonsoft.Json.Converters
}
EnsureReflectionObject(value.GetType());
Debug.Assert(_reflectionObject != null);
MiscellaneousUtils.Assert(_reflectionObject != null);
DefaultContractResolver? resolver = serializer.ContractResolver as DefaultContractResolver;
@@ -117,7 +117,7 @@ namespace Newtonsoft.Json.Converters
public override object? ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer)
{
EnsureReflectionObject(objectType);
Debug.Assert(_reflectionObject != null);
MiscellaneousUtils.Assert(_reflectionObject != null);
object entityKeyMember = _reflectionObject.Creator!();
@@ -57,7 +57,7 @@ namespace Newtonsoft.Json.Converters
public string? DateTimeFormat
{
get => _dateTimeFormat ?? string.Empty;
set => _dateTimeFormat = (string.IsNullOrEmpty(value)) ? null : value;
set => _dateTimeFormat = (StringUtils.IsNullOrEmpty(value)) ? null : value;
}
/// <summary>
@@ -162,7 +162,7 @@ namespace Newtonsoft.Json.Converters
string? dateText = reader.Value?.ToString();
if (string.IsNullOrEmpty(dateText) && nullable)
if (StringUtils.IsNullOrEmpty(dateText) && nullable)
{
return null;
}
@@ -170,7 +170,7 @@ namespace Newtonsoft.Json.Converters
#if HAVE_DATE_TIME_OFFSET
if (t == typeof(DateTimeOffset))
{
if (!string.IsNullOrEmpty(_dateTimeFormat))
if (!StringUtils.IsNullOrEmpty(_dateTimeFormat))
{
return DateTimeOffset.ParseExact(dateText, _dateTimeFormat, Culture, _dateTimeStyles);
}
@@ -181,7 +181,7 @@ namespace Newtonsoft.Json.Converters
}
#endif
if (!string.IsNullOrEmpty(_dateTimeFormat))
if (!StringUtils.IsNullOrEmpty(_dateTimeFormat))
{
return DateTime.ParseExact(dateText, _dateTimeFormat, Culture, _dateTimeStyles);
}
@@ -230,7 +230,7 @@ namespace Newtonsoft.Json.Converters
{
string? enumText = reader.Value?.ToString();
if (string.IsNullOrEmpty(enumText) && isNullable)
if (StringUtils.IsNullOrEmpty(enumText) && isNullable)
{
return null;
}
@@ -882,9 +882,9 @@ namespace Newtonsoft.Json.Converters
private bool HasImplicitNamespaceAttribute(string namespaceUri)
{
if (!string.IsNullOrEmpty(namespaceUri) && namespaceUri != ParentNode?.NamespaceUri)
if (!StringUtils.IsNullOrEmpty(namespaceUri) && namespaceUri != ParentNode?.NamespaceUri)
{
if (string.IsNullOrEmpty(GetPrefixOfNamespace(namespaceUri)))
if (StringUtils.IsNullOrEmpty(GetPrefixOfNamespace(namespaceUri)))
{
bool namespaceDeclared = false;
@@ -892,7 +892,7 @@ namespace Newtonsoft.Json.Converters
{
foreach (XAttribute attribute in Element.Attributes())
{
if (attribute.Name.LocalName == "xmlns" && string.IsNullOrEmpty(attribute.Name.NamespaceName) && attribute.Value == namespaceUri)
if (attribute.Name.LocalName == "xmlns" && StringUtils.IsNullOrEmpty(attribute.Name.NamespaceName) && attribute.Value == namespaceUri)
{
namespaceDeclared = true;
}
@@ -1072,7 +1072,7 @@ namespace Newtonsoft.Json.Converters
? null
: manager.LookupPrefix(node.NamespaceUri);
if (!string.IsNullOrEmpty(prefix))
if (!StringUtils.IsNullOrEmpty(prefix))
{
return prefix + ":" + XmlConvert.DecodeName(node.LocalName);
}
@@ -1405,17 +1405,17 @@ namespace Newtonsoft.Json.Converters
writer.WritePropertyName(GetPropertyName(node, manager));
writer.WriteStartObject();
if (!string.IsNullOrEmpty(declaration.Version))
if (!StringUtils.IsNullOrEmpty(declaration.Version))
{
writer.WritePropertyName("@version");
writer.WriteValue(declaration.Version);
}
if (!string.IsNullOrEmpty(declaration.Encoding))
if (!StringUtils.IsNullOrEmpty(declaration.Encoding))
{
writer.WritePropertyName("@encoding");
writer.WriteValue(declaration.Encoding);
}
if (!string.IsNullOrEmpty(declaration.Standalone))
if (!StringUtils.IsNullOrEmpty(declaration.Standalone))
{
writer.WritePropertyName("@standalone");
writer.WriteValue(declaration.Standalone);
@@ -1428,22 +1428,22 @@ namespace Newtonsoft.Json.Converters
writer.WritePropertyName(GetPropertyName(node, manager));
writer.WriteStartObject();
if (!string.IsNullOrEmpty(documentType.Name))
if (!StringUtils.IsNullOrEmpty(documentType.Name))
{
writer.WritePropertyName("@name");
writer.WriteValue(documentType.Name);
}
if (!string.IsNullOrEmpty(documentType.Public))
if (!StringUtils.IsNullOrEmpty(documentType.Public))
{
writer.WritePropertyName("@public");
writer.WriteValue(documentType.Public);
}
if (!string.IsNullOrEmpty(documentType.System))
if (!StringUtils.IsNullOrEmpty(documentType.System))
{
writer.WritePropertyName("@system");
writer.WriteValue(documentType.System);
}
if (!string.IsNullOrEmpty(documentType.InternalSubset))
if (!StringUtils.IsNullOrEmpty(documentType.InternalSubset))
{
writer.WritePropertyName("@internalSubset");
writer.WriteValue(documentType.InternalSubset);
@@ -1537,7 +1537,7 @@ namespace Newtonsoft.Json.Converters
throw JsonSerializationException.Create(reader, "Unexpected type when converting XML: " + objectType);
}
if (!string.IsNullOrEmpty(DeserializeRootElementName))
if (!StringUtils.IsNullOrEmpty(DeserializeRootElementName))
{
ReadElement(reader, document, rootNode, DeserializeRootElementName, manager);
}
@@ -1586,7 +1586,7 @@ namespace Newtonsoft.Json.Converters
return;
default:
// processing instructions and the xml declaration start with ?
if (!string.IsNullOrEmpty(propertyName) && propertyName[0] == '?')
if (!StringUtils.IsNullOrEmpty(propertyName) && propertyName[0] == '?')
{
CreateInstruction(reader, document, currentNode, propertyName);
return;
@@ -1616,7 +1616,7 @@ namespace Newtonsoft.Json.Converters
private void ReadElement(JsonReader reader, IXmlDocument document, IXmlNode currentNode, string propertyName, XmlNamespaceManager manager)
{
if (string.IsNullOrEmpty(propertyName))
if (StringUtils.IsNullOrEmpty(propertyName))
{
throw JsonSerializationException.Create(reader, "XmlNodeConverter cannot convert JSON with an empty property name to XML.");
}
@@ -1685,7 +1685,7 @@ namespace Newtonsoft.Json.Converters
string encodedName = XmlConvert.EncodeName(nameValue.Key);
string? attributePrefix = MiscellaneousUtils.GetPrefix(nameValue.Key);
IXmlNode attribute = (!string.IsNullOrEmpty(attributePrefix)) ? document.CreateAttribute(encodedName, manager.LookupNamespace(attributePrefix) ?? string.Empty, nameValue.Value) : document.CreateAttribute(encodedName, nameValue.Value);
IXmlNode attribute = (!StringUtils.IsNullOrEmpty(attributePrefix)) ? document.CreateAttribute(encodedName, manager.LookupNamespace(attributePrefix) ?? string.Empty, nameValue.Value) : document.CreateAttribute(encodedName, nameValue.Value);
element.SetAttributeNode(attribute);
}
@@ -1733,7 +1733,7 @@ namespace Newtonsoft.Json.Converters
string encodedName = XmlConvert.EncodeName(attributeName);
string? attributeValue = ConvertTokenToXmlValue(reader);
IXmlNode attribute = (!string.IsNullOrEmpty(attributePrefix))
IXmlNode attribute = (!StringUtils.IsNullOrEmpty(attributePrefix))
? document.CreateAttribute(encodedName, manager.LookupNamespace(attributePrefix), attributeValue)
: document.CreateAttribute(encodedName, attributeValue);
@@ -1876,7 +1876,7 @@ namespace Newtonsoft.Json.Converters
case JsonToken.PropertyName:
string attributeName = reader.Value!.ToString();
if (!string.IsNullOrEmpty(attributeName))
if (!StringUtils.IsNullOrEmpty(attributeName))
{
char firstChar = attributeName[0];
string? attributeValue;
@@ -2058,9 +2058,9 @@ namespace Newtonsoft.Json.Converters
private IXmlElement CreateElement(string elementName, IXmlDocument document, string? elementPrefix, XmlNamespaceManager manager)
{
string encodeName = EncodeSpecialCharacters ? XmlConvert.EncodeLocalName(elementName) : XmlConvert.EncodeName(elementName);
string ns = string.IsNullOrEmpty(elementPrefix) ? manager.DefaultNamespace : manager.LookupNamespace(elementPrefix);
string ns = StringUtils.IsNullOrEmpty(elementPrefix) ? manager.DefaultNamespace : manager.LookupNamespace(elementPrefix);
IXmlElement element = (!string.IsNullOrEmpty(ns)) ? document.CreateElement(encodeName, ns) : document.CreateElement(encodeName);
IXmlElement element = (!StringUtils.IsNullOrEmpty(ns)) ? document.CreateElement(encodeName, ns) : document.CreateElement(encodeName);
return element;
}
@@ -2092,7 +2092,7 @@ namespace Newtonsoft.Json.Converters
if (count == 1 && WriteArrayAttribute)
{
MiscellaneousUtils.GetQualifiedNameParts(propertyName, out string? elementPrefix, out string localName);
string ns = string.IsNullOrEmpty(elementPrefix) ? manager.DefaultNamespace : manager.LookupNamespace(elementPrefix);
string ns = StringUtils.IsNullOrEmpty(elementPrefix) ? manager.DefaultNamespace : manager.LookupNamespace(elementPrefix);
foreach (IXmlNode childNode in currentNode.ChildNodes)
{
+6 -6
View File
@@ -445,7 +445,7 @@ namespace Newtonsoft.Json
internal int? ReadInt32String(string? s)
{
if (string.IsNullOrEmpty(s))
if (StringUtils.IsNullOrEmpty(s))
{
SetToken(JsonToken.Null, null, false);
return null;
@@ -656,7 +656,7 @@ namespace Newtonsoft.Json
internal double? ReadDoubleString(string? s)
{
if (string.IsNullOrEmpty(s))
if (StringUtils.IsNullOrEmpty(s))
{
SetToken(JsonToken.Null, null, false);
return null;
@@ -715,7 +715,7 @@ namespace Newtonsoft.Json
internal bool? ReadBooleanString(string? s)
{
if (string.IsNullOrEmpty(s))
if (StringUtils.IsNullOrEmpty(s))
{
SetToken(JsonToken.Null, null, false);
return null;
@@ -786,7 +786,7 @@ namespace Newtonsoft.Json
internal decimal? ReadDecimalString(string? s)
{
if (string.IsNullOrEmpty(s))
if (StringUtils.IsNullOrEmpty(s))
{
SetToken(JsonToken.Null, null, false);
return null;
@@ -840,7 +840,7 @@ namespace Newtonsoft.Json
internal DateTime? ReadDateTimeString(string? s)
{
if (string.IsNullOrEmpty(s))
if (StringUtils.IsNullOrEmpty(s))
{
SetToken(JsonToken.Null, null, false);
return null;
@@ -895,7 +895,7 @@ namespace Newtonsoft.Json
internal DateTimeOffset? ReadDateTimeOffsetString(string? s)
{
if (string.IsNullOrEmpty(s))
if (StringUtils.IsNullOrEmpty(s))
{
SetToken(JsonToken.Null, null, false);
return null;
+20 -20
View File
@@ -111,7 +111,7 @@ namespace Newtonsoft.Json
private async Task<bool> ParsePostValueAsync(bool ignoreComments, CancellationToken cancellationToken)
{
Debug.Assert(_chars != null);
MiscellaneousUtils.Assert(_chars != null);
while (true)
{
@@ -196,7 +196,7 @@ namespace Newtonsoft.Json
private async Task<bool> ReadFromFinishedAsync(CancellationToken cancellationToken)
{
Debug.Assert(_chars != null);
MiscellaneousUtils.Assert(_chars != null);
if (await EnsureCharsAsync(0, false, cancellationToken).ConfigureAwait(false))
{
@@ -227,7 +227,7 @@ namespace Newtonsoft.Json
private async Task<int> ReadDataAsync(bool append, int charsRequired, CancellationToken cancellationToken)
{
Debug.Assert(_chars != null);
MiscellaneousUtils.Assert(_chars != null);
if (_isEndOfFile)
{
@@ -251,7 +251,7 @@ namespace Newtonsoft.Json
private async Task<bool> ParseValueAsync(CancellationToken cancellationToken)
{
Debug.Assert(_chars != null);
MiscellaneousUtils.Assert(_chars != null);
while (true)
{
@@ -382,7 +382,7 @@ namespace Newtonsoft.Json
private async Task ReadStringIntoBufferAsync(char quote, CancellationToken cancellationToken)
{
Debug.Assert(_chars != null);
MiscellaneousUtils.Assert(_chars != null);
int charPos = _charPos;
int initialPosition = _charPos;
@@ -600,7 +600,7 @@ namespace Newtonsoft.Json
private async Task<bool> ParseObjectAsync(CancellationToken cancellationToken)
{
Debug.Assert(_chars != null);
MiscellaneousUtils.Assert(_chars != null);
while (true)
{
@@ -659,7 +659,7 @@ namespace Newtonsoft.Json
private async Task ParseCommentAsync(bool setToken, CancellationToken cancellationToken)
{
Debug.Assert(_chars != null);
MiscellaneousUtils.Assert(_chars != null);
// should have already parsed / character before reaching this method
_charPos++;
@@ -757,7 +757,7 @@ namespace Newtonsoft.Json
private async Task EatWhitespaceAsync(CancellationToken cancellationToken)
{
Debug.Assert(_chars != null);
MiscellaneousUtils.Assert(_chars != null);
while (true)
{
@@ -815,7 +815,7 @@ namespace Newtonsoft.Json
private async Task<bool> MatchValueWithTrailingSeparatorAsync(string value, CancellationToken cancellationToken)
{
Debug.Assert(_chars != null);
MiscellaneousUtils.Assert(_chars != null);
// will match value and then move to the next character, checking that it is a separator character
if (!await MatchValueAsync(value, cancellationToken).ConfigureAwait(false))
@@ -860,7 +860,7 @@ namespace Newtonsoft.Json
private async Task ParseConstructorAsync(CancellationToken cancellationToken)
{
Debug.Assert(_chars != null);
MiscellaneousUtils.Assert(_chars != null);
if (await MatchValueWithTrailingSeparatorAsync("new", cancellationToken).ConfigureAwait(false))
{
@@ -960,7 +960,7 @@ namespace Newtonsoft.Json
private async Task ParseNumberAsync(ReadType readType, CancellationToken cancellationToken)
{
Debug.Assert(_chars != null);
MiscellaneousUtils.Assert(_chars != null);
ShiftBufferIfNeeded();
@@ -979,7 +979,7 @@ namespace Newtonsoft.Json
private async Task<bool> ParsePropertyAsync(CancellationToken cancellationToken)
{
Debug.Assert(_chars != null);
MiscellaneousUtils.Assert(_chars != null);
char firstChar = _chars[_charPos];
char quoteChar;
@@ -1033,7 +1033,7 @@ namespace Newtonsoft.Json
private async Task ReadNumberIntoBufferAsync(CancellationToken cancellationToken)
{
Debug.Assert(_chars != null);
MiscellaneousUtils.Assert(_chars != null);
int charPos = _charPos;
@@ -1069,7 +1069,7 @@ namespace Newtonsoft.Json
private async Task ParseUnquotedPropertyAsync(CancellationToken cancellationToken)
{
Debug.Assert(_chars != null);
MiscellaneousUtils.Assert(_chars != null);
int initialPosition = _charPos;
@@ -1120,7 +1120,7 @@ namespace Newtonsoft.Json
private async Task HandleNullAsync(CancellationToken cancellationToken)
{
Debug.Assert(_chars != null);
MiscellaneousUtils.Assert(_chars != null);
if (await EnsureCharsAsync(1, true, cancellationToken).ConfigureAwait(false))
{
@@ -1140,7 +1140,7 @@ namespace Newtonsoft.Json
private async Task ReadFinishedAsync(CancellationToken cancellationToken)
{
Debug.Assert(_chars != null);
MiscellaneousUtils.Assert(_chars != null);
if (await EnsureCharsAsync(0, false, cancellationToken).ConfigureAwait(false))
{
@@ -1167,7 +1167,7 @@ namespace Newtonsoft.Json
private async Task<object?> ReadStringValueAsync(ReadType readType, CancellationToken cancellationToken)
{
EnsureBuffer();
Debug.Assert(_chars != null);
MiscellaneousUtils.Assert(_chars != null);
switch (_currentState)
{
@@ -1303,7 +1303,7 @@ namespace Newtonsoft.Json
private async Task<object?> ReadNumberValueAsync(ReadType readType, CancellationToken cancellationToken)
{
EnsureBuffer();
Debug.Assert(_chars != null);
MiscellaneousUtils.Assert(_chars != null);
switch (_currentState)
{
@@ -1430,7 +1430,7 @@ namespace Newtonsoft.Json
internal async Task<bool?> DoReadAsBooleanAsync(CancellationToken cancellationToken)
{
EnsureBuffer();
Debug.Assert(_chars != null);
MiscellaneousUtils.Assert(_chars != null);
switch (_currentState)
{
@@ -1566,7 +1566,7 @@ namespace Newtonsoft.Json
internal async Task<byte[]?> DoReadAsBytesAsync(CancellationToken cancellationToken)
{
EnsureBuffer();
Debug.Assert(_chars != null);
MiscellaneousUtils.Assert(_chars != null);
bool isWrapped = false;
+30 -30
View File
@@ -138,7 +138,7 @@ namespace Newtonsoft.Json
private void SetNewLine(bool hasNextChar)
{
Debug.Assert(_chars != null);
MiscellaneousUtils.Assert(_chars != null);
if (hasNextChar && _chars[_charPos] == StringUtils.LineFeed)
{
@@ -252,7 +252,7 @@ namespace Newtonsoft.Json
private void ShiftBufferIfNeeded()
{
Debug.Assert(_chars != null);
MiscellaneousUtils.Assert(_chars != null);
// once in the last 10% of the buffer, or buffer is already very large then
// shift the remaining content to the start to avoid unnecessarily increasing
@@ -280,7 +280,7 @@ namespace Newtonsoft.Json
private void PrepareBufferForReadData(bool append, int charsRequired)
{
Debug.Assert(_chars != null);
MiscellaneousUtils.Assert(_chars != null);
// char buffer is full
if (_charsUsed + charsRequired >= _chars.Length - 1)
@@ -345,7 +345,7 @@ namespace Newtonsoft.Json
}
PrepareBufferForReadData(append, charsRequired);
Debug.Assert(_chars != null);
MiscellaneousUtils.Assert(_chars != null);
int attemptCharReadCount = _chars.Length - _charsUsed - 1;
@@ -414,7 +414,7 @@ namespace Newtonsoft.Json
public override bool Read()
{
EnsureBuffer();
Debug.Assert(_chars != null);
MiscellaneousUtils.Assert(_chars != null);
while (true)
{
@@ -497,7 +497,7 @@ namespace Newtonsoft.Json
public override byte[]? ReadAsBytes()
{
EnsureBuffer();
Debug.Assert(_chars != null);
MiscellaneousUtils.Assert(_chars != null);
bool isWrapped = false;
@@ -603,7 +603,7 @@ namespace Newtonsoft.Json
private object? ReadStringValue(ReadType readType)
{
EnsureBuffer();
Debug.Assert(_chars != null);
MiscellaneousUtils.Assert(_chars != null);
switch (_currentState)
{
@@ -770,7 +770,7 @@ namespace Newtonsoft.Json
public override bool? ReadAsBoolean()
{
EnsureBuffer();
Debug.Assert(_chars != null);
MiscellaneousUtils.Assert(_chars != null);
switch (_currentState)
{
@@ -908,7 +908,7 @@ namespace Newtonsoft.Json
private object? ReadNumberValue(ReadType readType)
{
EnsureBuffer();
Debug.Assert(_chars != null);
MiscellaneousUtils.Assert(_chars != null);
switch (_currentState)
{
@@ -1062,7 +1062,7 @@ namespace Newtonsoft.Json
private void HandleNull()
{
Debug.Assert(_chars != null);
MiscellaneousUtils.Assert(_chars != null);
if (EnsureChars(1, true))
{
@@ -1084,7 +1084,7 @@ namespace Newtonsoft.Json
private void ReadFinished()
{
Debug.Assert(_chars != null);
MiscellaneousUtils.Assert(_chars != null);
if (EnsureChars(0, false))
{
@@ -1135,7 +1135,7 @@ namespace Newtonsoft.Json
private void ReadStringIntoBuffer(char quote)
{
Debug.Assert(_chars != null);
MiscellaneousUtils.Assert(_chars != null);
int charPos = _charPos;
int initialPosition = _charPos;
@@ -1290,7 +1290,7 @@ namespace Newtonsoft.Json
private void FinishReadStringIntoBuffer(int charPos, int initialPosition, int lastWritePosition)
{
Debug.Assert(_chars != null);
MiscellaneousUtils.Assert(_chars != null);
if (initialPosition == lastWritePosition)
{
@@ -1313,7 +1313,7 @@ namespace Newtonsoft.Json
private void WriteCharToBuffer(char writeChar, int lastWritePosition, int writeToPosition)
{
Debug.Assert(_chars != null);
MiscellaneousUtils.Assert(_chars != null);
if (writeToPosition > lastWritePosition)
{
@@ -1325,7 +1325,7 @@ namespace Newtonsoft.Json
private char ConvertUnicode(bool enoughChars)
{
Debug.Assert(_chars != null);
MiscellaneousUtils.Assert(_chars != null);
if (enoughChars)
{
@@ -1353,7 +1353,7 @@ namespace Newtonsoft.Json
private void ReadNumberIntoBuffer()
{
Debug.Assert(_chars != null);
MiscellaneousUtils.Assert(_chars != null);
int charPos = _charPos;
@@ -1439,7 +1439,7 @@ namespace Newtonsoft.Json
private bool ParsePostValue(bool ignoreComments)
{
Debug.Assert(_chars != null);
MiscellaneousUtils.Assert(_chars != null);
while (true)
{
@@ -1521,7 +1521,7 @@ namespace Newtonsoft.Json
private bool ParseObject()
{
Debug.Assert(_chars != null);
MiscellaneousUtils.Assert(_chars != null);
while (true)
{
@@ -1577,7 +1577,7 @@ namespace Newtonsoft.Json
private bool ParseProperty()
{
Debug.Assert(_chars != null);
MiscellaneousUtils.Assert(_chars != null);
char firstChar = _chars[_charPos];
char quoteChar;
@@ -1640,7 +1640,7 @@ namespace Newtonsoft.Json
private void ParseUnquotedProperty()
{
Debug.Assert(_chars != null);
MiscellaneousUtils.Assert(_chars != null);
int initialPosition = _charPos;
@@ -1673,7 +1673,7 @@ namespace Newtonsoft.Json
private bool ReadUnquotedPropertyReportIfDone(char currentChar, int initialPosition)
{
Debug.Assert(_chars != null);
MiscellaneousUtils.Assert(_chars != null);
if (ValidIdentifierChar(currentChar))
{
@@ -1692,7 +1692,7 @@ namespace Newtonsoft.Json
private bool ParseValue()
{
Debug.Assert(_chars != null);
MiscellaneousUtils.Assert(_chars != null);
while (true)
{
@@ -1834,7 +1834,7 @@ namespace Newtonsoft.Json
private void EatWhitespace()
{
Debug.Assert(_chars != null);
MiscellaneousUtils.Assert(_chars != null);
while (true)
{
@@ -1877,7 +1877,7 @@ namespace Newtonsoft.Json
private void ParseConstructor()
{
Debug.Assert(_chars != null);
MiscellaneousUtils.Assert(_chars != null);
if (MatchValueWithTrailingSeparator("new"))
{
@@ -1963,7 +1963,7 @@ namespace Newtonsoft.Json
private void ParseNumber(ReadType readType)
{
ShiftBufferIfNeeded();
Debug.Assert(_chars != null);
MiscellaneousUtils.Assert(_chars != null);
char firstChar = _chars[_charPos];
int initialPosition = _charPos;
@@ -1975,7 +1975,7 @@ namespace Newtonsoft.Json
private void ParseReadNumber(ReadType readType, char firstChar, int initialPosition)
{
Debug.Assert(_chars != null);
MiscellaneousUtils.Assert(_chars != null);
// set state to PostValue now so that if there is an error parsing the number then the reader can continue
SetPostValueState(true);
@@ -2257,7 +2257,7 @@ namespace Newtonsoft.Json
private void ParseComment(bool setToken)
{
Debug.Assert(_chars != null);
MiscellaneousUtils.Assert(_chars != null);
// should have already parsed / character before reaching this method
_charPos++;
@@ -2364,7 +2364,7 @@ namespace Newtonsoft.Json
private bool MatchValue(bool enoughChars, string value)
{
Debug.Assert(_chars != null);
MiscellaneousUtils.Assert(_chars != null);
if (!enoughChars)
{
@@ -2388,7 +2388,7 @@ namespace Newtonsoft.Json
private bool MatchValueWithTrailingSeparator(string value)
{
Debug.Assert(_chars != null);
MiscellaneousUtils.Assert(_chars != null);
// will match value and then move to the next character, checking that it is a separator character
bool match = MatchValue(value);
@@ -2408,7 +2408,7 @@ namespace Newtonsoft.Json
private bool IsSeparator(char c)
{
Debug.Assert(_chars != null);
MiscellaneousUtils.Assert(_chars != null);
switch (c)
{
+4 -4
View File
@@ -165,7 +165,7 @@ namespace Newtonsoft.Json
int currentIndentCount = Top * _indentation;
int newLineLen = SetIndentChars();
Debug.Assert(_indentChars != null);
MiscellaneousUtils.Assert(_indentChars != null);
if (currentIndentCount <= IndentCharBufferSize)
{
@@ -177,7 +177,7 @@ namespace Newtonsoft.Json
private async Task WriteIndentAsync(int currentIndentCount, int newLineLen, CancellationToken cancellationToken)
{
Debug.Assert(_indentChars != null);
MiscellaneousUtils.Assert(_indentChars != null);
await _writer.WriteAsync(_indentChars, 0, newLineLen + Math.Min(currentIndentCount, IndentCharBufferSize), cancellationToken).ConfigureAwait(false);
@@ -657,7 +657,7 @@ namespace Newtonsoft.Json
await InternalWriteValueAsync(JsonToken.Date, cancellationToken).ConfigureAwait(false);
value = DateTimeUtils.EnsureDateTime(value, DateTimeZoneHandling);
if (string.IsNullOrEmpty(DateFormatString))
if (StringUtils.IsNullOrEmpty(DateFormatString))
{
int length = WriteValueToBuffer(value);
@@ -706,7 +706,7 @@ namespace Newtonsoft.Json
{
await InternalWriteValueAsync(JsonToken.Date, cancellationToken).ConfigureAwait(false);
if (string.IsNullOrEmpty(DateFormatString))
if (StringUtils.IsNullOrEmpty(DateFormatString))
{
int length = WriteValueToBuffer(value);
+6 -6
View File
@@ -633,7 +633,7 @@ namespace Newtonsoft.Json
InternalWriteValue(JsonToken.Date);
value = DateTimeUtils.EnsureDateTime(value, DateTimeZoneHandling);
if (string.IsNullOrEmpty(DateFormatString))
if (StringUtils.IsNullOrEmpty(DateFormatString))
{
int length = WriteValueToBuffer(value);
@@ -650,7 +650,7 @@ namespace Newtonsoft.Json
private int WriteValueToBuffer(DateTime value)
{
EnsureWriteBuffer();
Debug.Assert(_writeBuffer != null);
MiscellaneousUtils.Assert(_writeBuffer != null);
int pos = 0;
_writeBuffer[pos++] = _quoteChar;
@@ -688,7 +688,7 @@ namespace Newtonsoft.Json
{
InternalWriteValue(JsonToken.Date);
if (string.IsNullOrEmpty(DateFormatString))
if (StringUtils.IsNullOrEmpty(DateFormatString))
{
int length = WriteValueToBuffer(value);
@@ -705,7 +705,7 @@ namespace Newtonsoft.Json
private int WriteValueToBuffer(DateTimeOffset value)
{
EnsureWriteBuffer();
Debug.Assert(_writeBuffer != null);
MiscellaneousUtils.Assert(_writeBuffer != null);
int pos = 0;
_writeBuffer[pos++] = _quoteChar;
@@ -842,7 +842,7 @@ namespace Newtonsoft.Json
}
EnsureWriteBuffer();
Debug.Assert(_writeBuffer != null);
MiscellaneousUtils.Assert(_writeBuffer != null);
int totalLength = MathUtils.IntLength(value);
@@ -894,7 +894,7 @@ namespace Newtonsoft.Json
private int WriteNumberToBuffer(uint value, bool negative)
{
EnsureWriteBuffer();
Debug.Assert(_writeBuffer != null);
MiscellaneousUtils.Assert(_writeBuffer != null);
int totalLength = MathUtils.IntLength(value);
+1 -1
View File
@@ -72,7 +72,7 @@ namespace Newtonsoft.Json.Linq
parent = parent.Parent;
}
Debug.Assert(parent != null);
MiscellaneousUtils.Assert(parent != null);
switch (reader.TokenType)
{
+1 -1
View File
@@ -765,7 +765,7 @@ namespace Newtonsoft.Json.Linq
parent = parent.Parent;
}
Debug.Assert(parent != null);
MiscellaneousUtils.Assert(parent != null);
switch (r.TokenType)
{
+1 -1
View File
@@ -122,7 +122,7 @@ namespace Newtonsoft.Json.Linq
throw new IndexOutOfRangeException();
}
Debug.Assert(_token != null);
MiscellaneousUtils.Assert(_token != null);
return _token;
}
set
+2 -2
View File
@@ -315,9 +315,9 @@ namespace Newtonsoft.Json.Linq
_initialPath = _root.Path;
}
if (!string.IsNullOrEmpty(_initialPath))
if (!StringUtils.IsNullOrEmpty(_initialPath))
{
if (string.IsNullOrEmpty(path))
if (StringUtils.IsNullOrEmpty(path))
{
return _initialPath;
}
+1 -1
View File
@@ -356,7 +356,7 @@ namespace Newtonsoft.Json.Linq
}
byte[]? bytesA = objA as byte[];
Debug.Assert(bytesA != null);
MiscellaneousUtils.Assert(bytesA != null);
return MiscellaneousUtils.ByteArrayCompare(bytesA!, bytesB);
case JTokenType.Guid:
@@ -294,8 +294,8 @@ namespace Newtonsoft.Json.Linq.JsonPath
internal static bool EqualsWithStrictMatch(JValue value, JValue queryValue)
{
Debug.Assert(value != null);
Debug.Assert(queryValue != null);
MiscellaneousUtils.Assert(value != null);
MiscellaneousUtils.Assert(queryValue != null);
// Handle comparing an integer with a float
// e.g. Comparing 1 and 1.0
@@ -221,7 +221,7 @@ namespace Newtonsoft.Json.Schema
}
string location = token.Path.Replace(".", "/").Replace("[", "/").Replace("]", string.Empty);
if (!string.IsNullOrEmpty(location))
if (!StringUtils.IsNullOrEmpty(location))
{
location = "/" + location;
}
@@ -175,7 +175,7 @@ namespace Newtonsoft.Json.Schema
{
JsonContainerAttribute containerAttribute = JsonTypeReflector.GetCachedAttribute<JsonContainerAttribute>(type);
if (!string.IsNullOrEmpty(containerAttribute?.Title))
if (!StringUtils.IsNullOrEmpty(containerAttribute?.Title))
{
return containerAttribute.Title;
}
@@ -187,7 +187,7 @@ namespace Newtonsoft.Json.Schema
{
JsonContainerAttribute containerAttribute = JsonTypeReflector.GetCachedAttribute<JsonContainerAttribute>(type);
if (!string.IsNullOrEmpty(containerAttribute?.Description))
if (!StringUtils.IsNullOrEmpty(containerAttribute?.Description))
{
return containerAttribute.Description;
}
@@ -204,7 +204,7 @@ namespace Newtonsoft.Json.Schema
{
JsonContainerAttribute containerAttribute = JsonTypeReflector.GetCachedAttribute<JsonContainerAttribute>(type);
if (!string.IsNullOrEmpty(containerAttribute?.Id))
if (!StringUtils.IsNullOrEmpty(containerAttribute?.Id))
{
return containerAttribute.Id;
}
@@ -232,7 +232,7 @@ namespace Newtonsoft.Json.Schema
string resolvedId = GetTypeId(type, false);
string explicitId = GetTypeId(type, true);
if (!string.IsNullOrEmpty(resolvedId))
if (!StringUtils.IsNullOrEmpty(resolvedId))
{
JsonSchema resolvedSchema = _resolver.GetSchema(resolvedId);
if (resolvedSchema != null)
@@ -273,7 +273,7 @@ namespace Newtonsoft.Json.Serialization
{
if (_genericWrapperCreator == null)
{
Debug.Assert(_genericCollectionDefinitionType != null);
MiscellaneousUtils.Assert(_genericCollectionDefinitionType != null);
_genericWrapperType = typeof(CollectionWrapper<>).MakeGenericType(CollectionItemType);
@@ -307,7 +307,7 @@ namespace Newtonsoft.Json.Serialization
internal void WritePropertyName(JsonWriter writer)
{
string? propertyName = PropertyName;
Debug.Assert(propertyName != null);
MiscellaneousUtils.Assert(propertyName != null);
if (_skipPropertyNameEscape)
{
@@ -73,7 +73,7 @@ namespace Newtonsoft.Json.Serialization
/// <param name="property">The property to add to the collection.</param>
public void AddProperty(JsonProperty property)
{
Debug.Assert(property.PropertyName != null);
MiscellaneousUtils.Assert(property.PropertyName != null);
if (Contains(property.PropertyName))
{
@@ -351,7 +351,7 @@ namespace Newtonsoft.Json.Serialization
private static bool CoerceEmptyStringToNull(Type? objectType, JsonContract? contract, string s)
{
return string.IsNullOrEmpty(s) && objectType != null && objectType != typeof(string) && objectType != typeof(object) && contract != null && contract.IsNullable;
return StringUtils.IsNullOrEmpty(s) && objectType != null && objectType != typeof(string) && objectType != typeof(object) && contract != null && contract.IsNullable;
}
internal string GetExpectedDescription(JsonContract contract)
@@ -464,8 +464,8 @@ namespace Newtonsoft.Json.Serialization
return CreateJObject(reader);
}
Debug.Assert(resolvedObjectType != null);
Debug.Assert(contract != null);
MiscellaneousUtils.Assert(resolvedObjectType != null);
MiscellaneousUtils.Assert(contract != null);
switch (contract.ContractType)
{
@@ -840,8 +840,8 @@ namespace Newtonsoft.Json.Serialization
return CreateJToken(reader, contract);
}
Debug.Assert(objectType != null);
Debug.Assert(contract != null);
MiscellaneousUtils.Assert(objectType != null);
MiscellaneousUtils.Assert(contract != null);
JsonArrayContract arrayContract = EnsureArrayContract(reader, objectType, contract);
@@ -936,7 +936,7 @@ namespace Newtonsoft.Json.Serialization
return value;
}
Debug.Assert(contract != null);
MiscellaneousUtils.Assert(contract != null);
Type? valueType = ReflectionUtils.GetObjectType(value);
// type of value and type of target don't match
@@ -159,7 +159,7 @@ namespace Newtonsoft.Json.Serialization
return;
}
Debug.Assert(valueContract != null);
MiscellaneousUtils.Assert(valueContract != null);
JsonConverter? converter =
member?.Converter ??
@@ -252,7 +252,7 @@ namespace Newtonsoft.Json.Serialization
return false;
}
Debug.Assert(valueContract != null);
MiscellaneousUtils.Assert(valueContract != null);
if (valueContract.ContractType == JsonContractType.Primitive || valueContract.ContractType == JsonContractType.String)
{
@@ -304,7 +304,7 @@ namespace Newtonsoft.Json.Serialization
return true;
}
Debug.Assert(contract != null);
MiscellaneousUtils.Assert(contract != null);
if (contract.ContractType == JsonContractType.Primitive || contract.ContractType == JsonContractType.String)
{
+6 -6
View File
@@ -54,13 +54,13 @@ namespace Newtonsoft.Json.Utilities
// previous frameworks.
public static Task FromCanceled(this CancellationToken cancellationToken)
{
Debug.Assert(cancellationToken.IsCancellationRequested);
MiscellaneousUtils.Assert(cancellationToken.IsCancellationRequested);
return new Task(() => {}, cancellationToken);
}
public static Task<T> FromCanceled<T>(this CancellationToken cancellationToken)
{
Debug.Assert(cancellationToken.IsCancellationRequested);
MiscellaneousUtils.Assert(cancellationToken.IsCancellationRequested);
#pragma warning disable CS8653 // A default expression introduces a null value for a type parameter.
return new Task<T>(() => default, cancellationToken);
#pragma warning restore CS8653 // A default expression introduces a null value for a type parameter.
@@ -73,25 +73,25 @@ namespace Newtonsoft.Json.Utilities
public static Task WriteAsync(this TextWriter writer, char value, CancellationToken cancellationToken)
{
Debug.Assert(writer != null);
MiscellaneousUtils.Assert(writer != null);
return cancellationToken.IsCancellationRequested ? FromCanceled(cancellationToken) : writer.WriteAsync(value);
}
public static Task WriteAsync(this TextWriter writer, string? value, CancellationToken cancellationToken)
{
Debug.Assert(writer != null);
MiscellaneousUtils.Assert(writer != null);
return cancellationToken.IsCancellationRequested ? FromCanceled(cancellationToken) : writer.WriteAsync(value);
}
public static Task WriteAsync(this TextWriter writer, char[] value, int start, int count, CancellationToken cancellationToken)
{
Debug.Assert(writer != null);
MiscellaneousUtils.Assert(writer != null);
return cancellationToken.IsCancellationRequested ? FromCanceled(cancellationToken) : writer.WriteAsync(value, start, count);
}
public static Task<int> ReadAsync(this TextReader reader, char[] buffer, int index, int count, CancellationToken cancellationToken)
{
Debug.Assert(reader != null);
MiscellaneousUtils.Assert(reader != null);
return cancellationToken.IsCancellationRequested ? FromCanceled<int>(cancellationToken) : reader.ReadAsync(buffer, index, count);
}
@@ -364,7 +364,7 @@ namespace Newtonsoft.Json.Utilities
}
}
if (!string.IsNullOrEmpty(dateFormatString))
if (!StringUtils.IsNullOrEmpty(dateFormatString))
{
if (TryParseDateTimeExact(s.ToString(), dateTimeZoneHandling, dateFormatString, culture, out dt))
{
@@ -400,7 +400,7 @@ namespace Newtonsoft.Json.Utilities
}
}
if (!string.IsNullOrEmpty(dateFormatString))
if (!StringUtils.IsNullOrEmpty(dateFormatString))
{
if (TryParseDateTimeExact(s, dateTimeZoneHandling, dateFormatString, culture, out dt))
{
@@ -437,7 +437,7 @@ namespace Newtonsoft.Json.Utilities
}
}
if (!string.IsNullOrEmpty(dateFormatString))
if (!StringUtils.IsNullOrEmpty(dateFormatString))
{
if (TryParseDateTimeOffsetExact(s.ToString(), dateFormatString, culture, out dt))
{
@@ -475,7 +475,7 @@ namespace Newtonsoft.Json.Utilities
}
}
if (!string.IsNullOrEmpty(dateFormatString))
if (!StringUtils.IsNullOrEmpty(dateFormatString))
{
if (TryParseDateTimeOffsetExact(s, dateFormatString, culture, out dt))
{
@@ -620,7 +620,7 @@ namespace Newtonsoft.Json.Utilities
#region Write
internal static void WriteDateTimeString(TextWriter writer, DateTime value, DateFormatHandling format, string? formatString, CultureInfo culture)
{
if (string.IsNullOrEmpty(formatString))
if (StringUtils.IsNullOrEmpty(formatString))
{
char[] chars = new char[64];
int pos = WriteDateTimeString(chars, 0, value, null, value.Kind, format);
@@ -753,7 +753,7 @@ namespace Newtonsoft.Json.Utilities
#if HAVE_DATE_TIME_OFFSET
internal static void WriteDateTimeOffsetString(TextWriter writer, DateTimeOffset value, DateFormatHandling format, string? formatString, CultureInfo culture)
{
if (string.IsNullOrEmpty(formatString))
if (StringUtils.IsNullOrEmpty(formatString))
{
char[] chars = new char[64];
int pos = WriteDateTimeString(chars, 0, (format == DateFormatHandling.IsoDateFormat) ? value.DateTime : value.UtcDateTime, value.Offset, DateTimeKind.Local, format);
@@ -80,7 +80,7 @@ namespace Newtonsoft.Json.Utilities
{
get
{
Debug.Assert(_genericDictionary != null);
MiscellaneousUtils.Assert(_genericDictionary != null);
return _genericDictionary;
}
}
@@ -117,8 +117,8 @@ namespace Newtonsoft.Json.Utilities
{
#if !HAVE_REFLECTION_BINDER
Init();
Debug.Assert(_getMemberCall != null);
Debug.Assert(_getCSharpArgumentInfoArray != null);
MiscellaneousUtils.Assert(_getMemberCall != null);
MiscellaneousUtils.Assert(_getCSharpArgumentInfoArray != null);
return (CallSiteBinder)_getMemberCall(null, 0, name, context, _getCSharpArgumentInfoArray)!;
#else
return Binder.GetMember(
@@ -130,8 +130,8 @@ namespace Newtonsoft.Json.Utilities
{
#if !HAVE_REFLECTION_BINDER
Init();
Debug.Assert(_setMemberCall != null);
Debug.Assert(_setCSharpArgumentInfoArray != null);
MiscellaneousUtils.Assert(_setMemberCall != null);
MiscellaneousUtils.Assert(_setCSharpArgumentInfoArray != null);
return (CallSiteBinder)_setMemberCall(null, 0, name, context, _setCSharpArgumentInfoArray)!;
#else
return Binder.SetMember(
+1 -1
View File
@@ -94,7 +94,7 @@ namespace Newtonsoft.Json.Utilities
{
get
{
Debug.Assert(_instance != null);
MiscellaneousUtils.Assert(_instance != null);
return _instance;
}
}
@@ -153,7 +153,7 @@ namespace Newtonsoft.Json.Utilities
writer.Write(delimiter);
}
if (!string.IsNullOrEmpty(s))
if (!StringUtils.IsNullOrEmpty(s))
{
int lastWritePosition = FirstCharToEscape(s, charEscapeFlags, stringEscapeHandling);
if (lastWritePosition == -1)
@@ -266,7 +266,7 @@ namespace Newtonsoft.Json.Utilities
// copy it over when creating new buffer
if (isEscapedUnicodeText)
{
Debug.Assert(writeBuffer != null, "Write buffer should never be null because it is set when the escaped unicode text is encountered.");
MiscellaneousUtils.Assert(writeBuffer != null, "Write buffer should never be null because it is set when the escaped unicode text is encountered.");
Array.Copy(writeBuffer, newBuffer, UnicodeTextLength);
}
@@ -293,7 +293,7 @@ namespace Newtonsoft.Json.Utilities
}
}
Debug.Assert(lastWritePosition != 0);
MiscellaneousUtils.Assert(lastWritePosition != 0);
length = s.Length - lastWritePosition;
if (length > 0)
{
@@ -374,7 +374,7 @@ namespace Newtonsoft.Json.Utilities
return WriteEscapedJavaScriptStringWithDelimitersAsync(writer, s, delimiter, charEscapeFlags, stringEscapeHandling, client, writeBuffer, cancellationToken);
}
if (string.IsNullOrEmpty(s))
if (StringUtils.IsNullOrEmpty(s))
{
return cancellationToken.CancelIfRequestedAsync() ?? AsyncUtils.CompletedTask;
}
@@ -391,7 +391,7 @@ namespace Newtonsoft.Json.Utilities
return WriteEscapedJavaScriptStringWithDelimitersAsync(task, writer, s, delimiter, charEscapeFlags, stringEscapeHandling, client, writeBuffer, cancellationToken);
}
if (!string.IsNullOrEmpty(s))
if (!StringUtils.IsNullOrEmpty(s))
{
task = WriteEscapedJavaScriptStringWithoutDelimitersAsync(writer, s, charEscapeFlags, stringEscapeHandling, client, writeBuffer, cancellationToken);
if (task.IsCompletedSucessfully())
@@ -409,7 +409,7 @@ namespace Newtonsoft.Json.Utilities
{
await task.ConfigureAwait(false);
if (!string.IsNullOrEmpty(s))
if (!StringUtils.IsNullOrEmpty(s))
{
await WriteEscapedJavaScriptStringWithoutDelimitersAsync(writer, s, charEscapeFlags, stringEscapeHandling, client, writeBuffer, cancellationToken).ConfigureAwait(false);
}
+4 -4
View File
@@ -377,7 +377,7 @@ namespace Newtonsoft.Json.Utilities.LinqBridge
Func<TSource> empty)
{
CheckNotNull(source, "source");
Debug.Assert(empty != null);
MiscellaneousUtils.Assert(empty != null);
var list = source as IList<TSource>; // optimized case for lists
if (list != null)
@@ -1364,7 +1364,7 @@ namespace Newtonsoft.Json.Utilities.LinqBridge
Func<TSource, TSource, bool> lesser)
{
CheckNotNull(source, "source");
Debug.Assert(lesser != null);
MiscellaneousUtils.Assert(lesser != null);
return source.Aggregate((a, item) => lesser(a, item) ? a : item);
}
@@ -1378,7 +1378,7 @@ namespace Newtonsoft.Json.Utilities.LinqBridge
TSource? seed, Func<TSource?, TSource?, bool> lesser) where TSource : struct
{
CheckNotNull(source, "source");
Debug.Assert(lesser != null);
MiscellaneousUtils.Assert(lesser != null);
return source.Aggregate(seed, (a, item) => lesser(a, item) ? a : item);
// == MinMaxImpl(Repeat<TSource?>(null, 1).Concat(source), lesser);
@@ -1442,7 +1442,7 @@ namespace Newtonsoft.Json.Utilities.LinqBridge
private static IEnumerable<T> Renumerable<T>(this IEnumerator<T> e)
{
Debug.Assert(e != null);
MiscellaneousUtils.Assert(e != null);
do
{
@@ -31,6 +31,8 @@ using System.Reflection;
using System.Text;
using System.Globalization;
using System.Text.RegularExpressions;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
namespace Newtonsoft.Json.Utilities
{
@@ -38,6 +40,12 @@ namespace Newtonsoft.Json.Utilities
internal static class MiscellaneousUtils
{
[Conditional("DEBUG")]
public static void Assert([DoesNotReturnIf(false)] bool condition, string? message = null)
{
Debug.Assert(condition, message);
}
public static bool ValueEquals(object? objA, object? objB)
{
if (objA == objB)
@@ -52,4 +52,23 @@ namespace System.Diagnostics.CodeAnalysis
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property, Inherited = false)]
internal sealed class AllowNullAttribute : Attribute
{ }
/// <summary>
/// Specifies that the method will not return if the associated Boolean parameter is passed the specified value.
/// </summary>
[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
internal class DoesNotReturnIfAttribute : Attribute
{
/// <summary>
/// Initializes a new instance of the <see cref="DoesNotReturnIfAttribute"/> class.
/// </summary>
/// <param name="parameterValue">
/// The condition parameter value. Code after the method will be considered unreachable by diagnostics if the argument to
/// the associated parameter matches this value.
/// </param>
public DoesNotReturnIfAttribute(bool parameterValue) => this.ParameterValue = parameterValue;
/// <summary>Gets the condition parameter value.</summary>
public bool ParameterValue { get; }
}
}
+8 -2
View File
@@ -28,6 +28,7 @@ using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics.CodeAnalysis;
#if !HAVE_LINQ
using Newtonsoft.Json.Utilities.LinqBridge;
#else
@@ -45,6 +46,11 @@ namespace Newtonsoft.Json.Utilities
public const char LineFeed = '\n';
public const char Tab = '\t';
public static bool IsNullOrEmpty([NotNullWhen(false)] string? value)
{
return string.IsNullOrEmpty(value);
}
public static string FormatWith(this string format, IFormatProvider provider, object? arg0)
{
return format.FormatWith(provider, new object?[] { arg0 });
@@ -148,7 +154,7 @@ namespace Newtonsoft.Json.Utilities
public static string ToCamelCase(string s)
{
if (string.IsNullOrEmpty(s) || !char.IsUpper(s[0]))
if (StringUtils.IsNullOrEmpty(s) || !char.IsUpper(s[0]))
{
return s;
}
@@ -207,7 +213,7 @@ namespace Newtonsoft.Json.Utilities
public static string ToSnakeCase(string s)
{
if (string.IsNullOrEmpty(s))
if (StringUtils.IsNullOrEmpty(s))
{
return s;
}