public void LargeModeSerialize() { var sharedDictionary = new SharedDictionary(new SystemTextJsonSerializer(SerializeMode.LargeObject), null, null); sharedDictionary.RawImport(Encoding.UTF8.GetBytes(JsonConstant.LargeModeJson)); Assert.AreEqual(sharedDictionary.GetProperty <string>("key1"), "string"); Assert.AreEqual(sharedDictionary.GetProperty <int>("key2"), 1); }
public void ShortModeSerialize() { var sharedDictionary = new SharedDictionary(SpanJsonSerializer.Create(SerializeMode.ShortObject), null, null); sharedDictionary.RawImport(Encoding.UTF8.GetBytes(JsonConstant.ShortModeJson)); Assert.AreEqual(sharedDictionary.GetProperty <string>("key1"), "string"); Assert.AreEqual(sharedDictionary.GetProperty <int>("key2"), 1); }
public void LargeModeNullValue() { var sharedDictionary = new SharedDictionary(new SystemTextJsonSerializer(SerializeMode.LargeObject), null, null); sharedDictionary.SetProperty <int?>("nullableInt", null); sharedDictionary.SetProperty <string?>("nullableString", null); byte[] binary = sharedDictionary.RawExport(); sharedDictionary.ClearProperty(); Assert.AreEqual(0, sharedDictionary.PropertyCount); sharedDictionary.RawImport(binary); Assert.AreEqual(null, sharedDictionary.GetProperty <int?>("nullableInt")); Assert.AreEqual(null, sharedDictionary.GetProperty <string?>("nullableString")); }
public void TestImplicitOperator2() { var sharedDictionary = new SharedDictionary(EmptySerializer.Default, null, null); sharedDictionary.SetProperty(key, new ImplicitOperatableSource2()); sharedDictionary.GetProperty <ImplicitOperatableTarget2>(key); }
public void TestNullable() { var sharedDictionary = new SharedDictionary(EmptySerializer.Default, null, null); sharedDictionary.SetProperty <NullableData>(key, new NullableData()); sharedDictionary.GetProperty <NullableData?>(key); }
public void TestContravariance() { var sharedDictionary = new SharedDictionary(EmptySerializer.Default, null, null); sharedDictionary.SetProperty(key, new Contravariance <object>()); sharedDictionary.GetProperty <IContravariance <string> >(key); }
public void TestUpcast() { var sharedDictionary = new SharedDictionary(EmptySerializer.Default, null, null); sharedDictionary.SetProperty(key, "value"); sharedDictionary.GetProperty <object>(key); }
public void LargeModeSerializeWithUnknownData() { var sharedDictionary = new SharedDictionary(new SystemTextJsonSerializer(SerializeMode.LargeObject), null, null); sharedDictionary.RawImport(Encoding.UTF8.GetBytes(JsonConstant.LargeModeJsonWithUnknownData)); Assert.AreEqual(sharedDictionary.PropertyCount, 1); Assert.AreEqual(sharedDictionary.GetProperty <int>("key2"), 1); }
public void ShortModeSerializeWithUnknownData() { var sharedDictionary = new SharedDictionary(SpanJsonSerializer.Create(SerializeMode.ShortObject), null, null); sharedDictionary.RawImport(Encoding.UTF8.GetBytes(JsonConstant.ShortModeJsonWithUnknownData)); Assert.AreEqual(sharedDictionary.PropertyCount, 1); Assert.AreEqual(sharedDictionary.GetProperty <int>("key2"), 1); }
public static async Task Main(string[] args) { var sharedDictionary = new SharedDictionary(Utf8JsonSerializer.Default, FileStorage.Default, null); sharedDictionary.SetProperty("text", "sssss"); sharedDictionary.SetProperty("number", 1234); sharedDictionary.SetProperty("data", new Data()); sharedDictionary.SetProperty("list", new List <int> { 1, 2, 3, 4 }); await sharedDictionary.SaveToStorageAsync(); sharedDictionary = new SharedDictionary(Utf8JsonSerializer.Default, FileStorage.Default, null); await sharedDictionary.LoadFromStorageAsync(); foreach (var property in sharedDictionary) { WriteLine($"key: {property.Key}"); } WriteLine(sharedDictionary.GetProperty <string>("text")); WriteLine(sharedDictionary.GetProperty <int>("number")); WriteLine(sharedDictionary.GetProperty <long>("number")); WriteLine(sharedDictionary.GetProperty <Data>("data")); WriteLine(sharedDictionary.GetProperty <List <int> >("list")?.Count); WriteLine(sharedDictionary.GetProperty <IEnumerable <int> >("list").Count()); var serializer = new Utf8JsonSerializer(); serializer.MigrationTypeDictionary[TypeCache <Data> .FullName] = TypeCache <MigratedData> .FullName; sharedDictionary = new SharedDictionary(serializer, FileStorage.Default, null); await sharedDictionary.LoadFromStorageAsync(); WriteLine($"MigratedData: {sharedDictionary.GetProperty<MigratedData>("data")}"); }