mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.5 KiB
42 lines
1.5 KiB
// ==========================================================================
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex UG (haftungsbeschränkt)
|
|
// All rights reserved. Licensed under the MIT license.
|
|
// ==========================================================================
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Newtonsoft.Json;
|
|
using Squidex.Infrastructure.Json.Newtonsoft;
|
|
|
|
namespace Squidex.Domain.Apps.Core.Apps.Json
|
|
{
|
|
public sealed class AppPatternsConverter : JsonClassConverter<AppPatterns>
|
|
{
|
|
protected override void WriteValue(JsonWriter writer, AppPatterns value, JsonSerializer serializer)
|
|
{
|
|
var json = new Dictionary<Guid, JsonAppPattern>(value.Count);
|
|
|
|
foreach (var (key, appPattern) in value)
|
|
{
|
|
json.Add(key, new JsonAppPattern(appPattern));
|
|
}
|
|
|
|
serializer.Serialize(writer, json);
|
|
}
|
|
|
|
protected override AppPatterns ReadValue(JsonReader reader, Type objectType, JsonSerializer serializer)
|
|
{
|
|
var json = serializer.Deserialize<Dictionary<Guid, JsonAppPattern>>(reader);
|
|
|
|
return new AppPatterns(json.Select(Convert).ToArray());
|
|
}
|
|
|
|
private static KeyValuePair<Guid, AppPattern> Convert(KeyValuePair<Guid, JsonAppPattern> kvp)
|
|
{
|
|
return new KeyValuePair<Guid, AppPattern>(kvp.Key, kvp.Value.ToPattern());
|
|
}
|
|
}
|
|
}
|
|
|