File: UnifiedSettings\TestModel\ResourceStringArrayConverter.cs
Web Access
Project: src\src\VisualStudio\Core\Test.Next\Roslyn.VisualStudio.Next.UnitTests.csproj (Roslyn.VisualStudio.Next.UnitTests)
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
 
using System;
using System.Text.Json;
using System.Text.Json.Serialization;
using Microsoft.CodeAnalysis.PooledObjects;
 
namespace Roslyn.VisualStudio.Next.UnitTests.UnifiedSettings.TestModel;
 
internal class ResourceStringArrayConverter : JsonConverter<string[]>
{
    public override string[] Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
    {
        if (reader.TokenType != JsonTokenType.StartArray)
            throw new JsonException("Expected StartArray token");
 
        using var _ = ArrayBuilder<string>.GetInstance(out var builder);
        while (reader.Read())
        {
            if (reader.TokenType == JsonTokenType.EndArray)
                break;
 
            if (reader.TokenType == JsonTokenType.String)
            {
                var value = reader.GetString()!;
                builder.Add(Utilities.EvalResource(value)!);
            }
            else
            {
                throw new JsonException("Token should be string");
            }
        }
 
        return builder.ToArray();
    }
 
    public override void Write(Utf8JsonWriter writer, string[] value, JsonSerializerOptions options)
    {
        throw new NotImplementedException();
    }
}