internal static TextLine DeserializeTextLine(JsonElement element)
        {
            string text = default;
            IReadOnlyList <float>    boundingBox = default;
            Optional <Language>      language    = default;
            IReadOnlyList <TextWord> words       = default;
            Optional <Appearance>    appearance  = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("text"))
                {
                    text = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("boundingBox"))
                {
                    List <float> array = new List <float>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(item.GetSingle());
                    }
                    boundingBox = array;
                    continue;
                }
                if (property.NameEquals("language"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    language = new Language(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("words"))
                {
                    List <TextWord> array = new List <TextWord>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(TextWord.DeserializeTextWord(item));
                    }
                    words = array;
                    continue;
                }
                if (property.NameEquals("appearance"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    appearance = Appearance.DeserializeAppearance(property.Value);
                    continue;
                }
            }
            return(new TextLine(text, boundingBox, Optional.ToNullable(language), words, appearance.Value));
        }
Ejemplo n.º 2
0
        internal static TextLine DeserializeTextLine(JsonElement element)
        {
            string text = default;
            IReadOnlyList <float> boundingBox = default;
            Language?language = default;
            IReadOnlyList <TextWord> words = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("text"))
                {
                    text = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("boundingBox"))
                {
                    List <float> array = new List <float>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(item.GetSingle());
                    }
                    boundingBox = array;
                    continue;
                }
                if (property.NameEquals("language"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    language = new Language(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("words"))
                {
                    List <TextWord> array = new List <TextWord>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        if (item.ValueKind == JsonValueKind.Null)
                        {
                            array.Add(null);
                        }
                        else
                        {
                            array.Add(TextWord.DeserializeTextWord(item));
                        }
                    }
                    words = array;
                    continue;
                }
            }
            return(new TextLine(text, boundingBox, language, words));
        }