Пример #1
0
        internal static Analyzer DeserializeAnalyzer(JsonElement element)
        {
            if (element.TryGetProperty("@odata.type", out JsonElement discriminator))
            {
                switch (discriminator.GetString())
                {
                case "#Microsoft.Azure.Search.CustomAnalyzer": return(CustomAnalyzer.DeserializeCustomAnalyzer(element));

                case "#Microsoft.Azure.Search.PatternAnalyzer": return(PatternAnalyzer.DeserializePatternAnalyzer(element));

                case "#Microsoft.Azure.Search.StandardAnalyzer": return(StandardAnalyzer.DeserializeStandardAnalyzer(element));

                case "#Microsoft.Azure.Search.StopAnalyzer": return(StopAnalyzer.DeserializeStopAnalyzer(element));
                }
            }
            string odatatype = default;
            string name      = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("@odata.type"))
                {
                    odatatype = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("name"))
                {
                    name = property.Value.GetString();
                    continue;
                }
            }
            return(new Analyzer(odatatype, name));
        }
        internal static PatternAnalyzer DeserializePatternAnalyzer(JsonElement element)
        {
            PatternAnalyzer result = new PatternAnalyzer();

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("lowercase"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    result.LowerCaseTerms = property.Value.GetBoolean();
                    continue;
                }
                if (property.NameEquals("pattern"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    result.Pattern = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("flags"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    result.Flags = new RegexFlags(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("stopwords"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    result.Stopwords = new List <string>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        result.Stopwords.Add(item.GetString());
                    }
                    continue;
                }
                if (property.NameEquals("@odata.type"))
                {
                    result.ODataType = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("name"))
                {
                    result.Name = property.Value.GetString();
                    continue;
                }
            }
            return(result);
        }