forked from unoplatform/uno
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Remove dependency on System.Json package
This change is needed to enable compatibility with .NET 6
- Loading branch information
1 parent
b0db479
commit 46a2856
Showing
10 changed files
with
1,407 additions
and
5 deletions.
There are no files selected for viewing
436 changes: 436 additions & 0 deletions
436
src/AddIns/Uno.UI.Lottie/System.Json/JavaScriptReader.cs
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// See the LICENSE file in the project root for more information. | ||
// Export from https://github.com/dotnet/corefx/commit/f398b6f7c3d08d8e437939cbd9ef29cb3beda1db | ||
#nullable disable | ||
|
||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
|
||
namespace System.Json | ||
{ | ||
public class JsonArray : JsonValue, IList<JsonValue> | ||
{ | ||
private readonly List<JsonValue> _list; | ||
|
||
public JsonArray(params JsonValue[] items) | ||
{ | ||
_list = new List<JsonValue>(); | ||
AddRange(items); | ||
} | ||
|
||
public JsonArray(IEnumerable<JsonValue> items) | ||
{ | ||
if (items == null) | ||
{ | ||
throw new ArgumentNullException(nameof(items)); | ||
} | ||
|
||
_list = new List<JsonValue>(items); | ||
} | ||
|
||
public override int Count => _list.Count; | ||
|
||
public bool IsReadOnly => false; | ||
|
||
public override sealed JsonValue this[int index] | ||
{ | ||
get { return _list[index]; } | ||
set { _list[index] = value; } | ||
} | ||
|
||
public override JsonType JsonType => JsonType.Array; | ||
|
||
public void Add(JsonValue item) | ||
{ | ||
_list.Add(item); | ||
} | ||
|
||
public void AddRange(IEnumerable<JsonValue> items) | ||
{ | ||
if (items == null) | ||
{ | ||
throw new ArgumentNullException(nameof(items)); | ||
} | ||
|
||
_list.AddRange(items); | ||
} | ||
|
||
public void AddRange(params JsonValue[] items) | ||
{ | ||
if (items != null) | ||
{ | ||
_list.AddRange(items); | ||
} | ||
} | ||
|
||
public void Clear() => _list.Clear(); | ||
|
||
public bool Contains(JsonValue item) => _list.Contains(item); | ||
|
||
public void CopyTo(JsonValue[] array, int arrayIndex) => _list.CopyTo(array, arrayIndex); | ||
|
||
public int IndexOf(JsonValue item) => _list.IndexOf(item); | ||
|
||
public void Insert(int index, JsonValue item) => _list.Insert(index, item); | ||
|
||
public bool Remove(JsonValue item) => _list.Remove(item); | ||
|
||
public void RemoveAt(int index) => _list.RemoveAt(index); | ||
|
||
public override void Save(Stream stream) | ||
{ | ||
if (stream == null) | ||
{ | ||
throw new ArgumentNullException(nameof(stream)); | ||
} | ||
|
||
stream.WriteByte((byte)'['); | ||
|
||
for (int i = 0; i < _list.Count; i++) | ||
{ | ||
JsonValue v = _list[i]; | ||
if (v != null) | ||
{ | ||
v.Save(stream); | ||
} | ||
else | ||
{ | ||
stream.WriteByte((byte)'n'); | ||
stream.WriteByte((byte)'u'); | ||
stream.WriteByte((byte)'l'); | ||
stream.WriteByte((byte)'l'); | ||
} | ||
|
||
if (i < Count - 1) | ||
{ | ||
stream.WriteByte((byte)','); | ||
stream.WriteByte((byte)' '); | ||
} | ||
} | ||
|
||
stream.WriteByte((byte)']'); | ||
} | ||
|
||
IEnumerator<JsonValue> IEnumerable<JsonValue>.GetEnumerator() => _list.GetEnumerator(); | ||
|
||
IEnumerator IEnumerable.GetEnumerator() => _list.GetEnumerator(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// See the LICENSE file in the project root for more information. | ||
// Export from https://github.com/dotnet/corefx/commit/f398b6f7c3d08d8e437939cbd9ef29cb3beda1db | ||
#nullable disable | ||
|
||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Text; | ||
|
||
using JsonPair = System.Collections.Generic.KeyValuePair<string, System.Json.JsonValue>; | ||
using JsonPairEnumerable = System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, System.Json.JsonValue>>; | ||
|
||
namespace System.Json | ||
{ | ||
public class JsonObject : JsonValue, IDictionary<string, JsonValue>, ICollection<JsonPair> | ||
{ | ||
// Use SortedDictionary to make result of ToString() deterministic | ||
private readonly SortedDictionary<string, JsonValue> _map; | ||
|
||
public JsonObject(params JsonPair[] items) | ||
{ | ||
_map = new SortedDictionary<string, JsonValue>(StringComparer.Ordinal); | ||
|
||
if (items != null) | ||
{ | ||
AddRange(items); | ||
} | ||
} | ||
|
||
public JsonObject(JsonPairEnumerable items) | ||
{ | ||
if (items == null) | ||
{ | ||
throw new ArgumentNullException(nameof(items)); | ||
} | ||
|
||
_map = new SortedDictionary<string, JsonValue>(StringComparer.Ordinal); | ||
AddRange(items); | ||
} | ||
|
||
public override int Count => _map.Count; | ||
|
||
public IEnumerator<JsonPair> GetEnumerator() => _map.GetEnumerator(); | ||
|
||
IEnumerator IEnumerable.GetEnumerator() => _map.GetEnumerator(); | ||
|
||
public override sealed JsonValue this[string key] | ||
{ | ||
get { return _map[key]; } | ||
set { _map[key] = value; } | ||
} | ||
|
||
public override JsonType JsonType => JsonType.Object; | ||
|
||
public ICollection<string> Keys => _map.Keys; | ||
|
||
public ICollection<JsonValue> Values => _map.Values; | ||
|
||
public void Add(string key, JsonValue value) | ||
{ | ||
if (key == null) | ||
{ | ||
throw new ArgumentNullException(nameof(key)); | ||
} | ||
|
||
_map.Add(key, value); | ||
} | ||
|
||
public void Add(JsonPair pair) => Add(pair.Key, pair.Value); | ||
|
||
public void AddRange(JsonPairEnumerable items) | ||
{ | ||
if (items == null) | ||
{ | ||
throw new ArgumentNullException(nameof(items)); | ||
} | ||
|
||
foreach (var pair in items) | ||
{ | ||
_map.Add(pair.Key, pair.Value); | ||
} | ||
} | ||
|
||
public void AddRange(params JsonPair[] items) => AddRange((JsonPairEnumerable)items); | ||
|
||
public void Clear() => _map.Clear(); | ||
|
||
bool ICollection<JsonPair>.Contains(JsonPair item) => (_map as ICollection<JsonPair>).Contains(item); | ||
|
||
bool ICollection<JsonPair>.Remove(JsonPair item) => (_map as ICollection<JsonPair>).Remove(item); | ||
|
||
public override bool ContainsKey(string key) | ||
{ | ||
if (key == null) | ||
{ | ||
throw new ArgumentNullException(nameof(key)); | ||
} | ||
|
||
return _map.ContainsKey(key); | ||
} | ||
|
||
public void CopyTo(JsonPair[] array, int arrayIndex) => (_map as ICollection<JsonPair>).CopyTo(array, arrayIndex); | ||
|
||
public bool Remove(string key) | ||
{ | ||
if (key == null) | ||
{ | ||
throw new ArgumentNullException(nameof(key)); | ||
} | ||
|
||
return _map.Remove(key); | ||
} | ||
|
||
bool ICollection<JsonPair>.IsReadOnly => false; | ||
|
||
public override void Save(Stream stream) | ||
{ | ||
base.Save(stream); | ||
} | ||
|
||
public bool TryGetValue(string key, out JsonValue value) => _map.TryGetValue(key, out value); | ||
} | ||
} |
Oops, something went wrong.