public JsonPropertyInfo GetProperty(ReadOnlySpan <byte> propertyName, int propertyIndex) { ulong key = GetKey(propertyName); JsonPropertyInfo info = null; // First try sorted lookup. int count = _property_refs_sorted.Count; if (count != 0) { int iForward = propertyIndex; int iBackward = propertyIndex - 1; while (iForward < count || (iBackward >= 0 && iBackward < count)) { if (iForward < count) { if (TryIsPropertyRefEqual(_property_refs_sorted, propertyName, key, iForward, out info)) { return(info); } ++iForward; } if (iBackward >= 0) { if (TryIsPropertyRefEqual(_property_refs_sorted, propertyName, key, iBackward, out info)) { return(info); } --iBackward; } } } // Then try fallback for (int i = 0; i < _property_refs.Count; i++) { if (TryIsPropertyRefEqual(_property_refs, propertyName, key, i, out info)) { break; } } if (info == null) { string stringPropertyName = JsonReaderHelper.TranscodeHelper(propertyName); throw new InvalidOperationException($"todo: invalid property {stringPropertyName}"); } _property_refs_sorted.Add(new PropertyRef(key, info)); return(info); }
private static string WriteCoreString(object value, Type type, JsonSerializerOptions options) { options ??= JsonSerializerOptions.s_defaultOptions; string result; using (var output = new ArrayBufferWriter <byte>(options.DefaultBufferSize)) { WriteCore(output, value, type, options); result = JsonReaderHelper.TranscodeHelper(output.WrittenMemory.Span); } return(result); }