internal static JsonTokenInfo[] GetTokensFromObjectNode(IJsonNavigatorNode node, IJsonNavigator navigator, bool performCorrectnessCheck) { // Get the tokens through .GetObjectProperties List <JsonTokenInfo> tokensFromGetProperties = new List <JsonTokenInfo>(); IEnumerable <ObjectProperty> properties = navigator.GetObjectProperties(node); tokensFromGetProperties.Add(JsonTokenInfo.ObjectStart()); foreach (ObjectProperty property in properties) { string fieldname = navigator.GetStringValue(property.NameNode); tokensFromGetProperties.Add(JsonTokenInfo.FieldName(fieldname)); tokensFromGetProperties.AddRange(JsonNavigatorTests.GetTokensFromNode(property.ValueNode, navigator, performCorrectnessCheck)); } tokensFromGetProperties.Add(JsonTokenInfo.ObjectEnd()); if (performCorrectnessCheck) { // Get the tokens again through .TryGetObjectProperty List <JsonTokenInfo> tokensFromTryGetProperty = new List <JsonTokenInfo>(); tokensFromTryGetProperty.Add(JsonTokenInfo.ObjectStart()); foreach (ObjectProperty objectProperty in properties) { ObjectProperty propertyFromTryGetProperty; string fieldname = navigator.GetStringValue(objectProperty.NameNode); if (navigator.TryGetObjectProperty(node, fieldname, out propertyFromTryGetProperty)) { tokensFromTryGetProperty.Add(JsonTokenInfo.FieldName(fieldname)); tokensFromTryGetProperty.AddRange(JsonNavigatorTests.GetTokensFromNode(propertyFromTryGetProperty.ValueNode, navigator, performCorrectnessCheck)); } else { Assert.Fail($"Failed to get object property with name: {fieldname}"); } } tokensFromTryGetProperty.Add(JsonTokenInfo.ObjectEnd()); Assert.AreEqual(properties.Count(), navigator.GetObjectPropertyCount(node)); Assert.IsTrue(tokensFromGetProperties.SequenceEqual(tokensFromTryGetProperty)); } return(tokensFromGetProperties.ToArray()); }