Ejemplo n.º 1
0
 internal Index(string name, IList <Field> fields, IList <ScoringProfile> scoringProfiles, string defaultScoringProfile, CorsOptions corsOptions, IList <Suggester> suggesters, IList <Analyzer> analyzers, IList <Tokenizer> tokenizers, IList <TokenFilter> tokenFilters, IList <CharFilter> charFilters, EncryptionKey encryptionKey, Similarity similarity, string eTag)
 {
     Name                  = name;
     Fields                = fields;
     ScoringProfiles       = scoringProfiles;
     DefaultScoringProfile = defaultScoringProfile;
     CorsOptions           = corsOptions;
     Suggesters            = suggesters;
     Analyzers             = analyzers;
     Tokenizers            = tokenizers;
     TokenFilters          = tokenFilters;
     CharFilters           = charFilters;
     EncryptionKey         = encryptionKey;
     Similarity            = similarity;
     ETag                  = eTag;
 }
        internal static Index DeserializeIndex(JsonElement element)
        {
            string                 name                  = default;
            IList <Field>          fields                = default;
            IList <ScoringProfile> scoringProfiles       = default;
            string                 defaultScoringProfile = default;
            CorsOptions            corsOptions           = default;
            IList <Suggester>      suggesters            = default;
            IList <Analyzer>       analyzers             = default;
            IList <Tokenizer>      tokenizers            = default;
            IList <TokenFilter>    tokenFilters          = default;
            IList <CharFilter>     charFilters           = default;
            EncryptionKey          encryptionKey         = default;
            Similarity             similarity            = default;
            string                 odataEtag             = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("name"))
                {
                    name = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("fields"))
                {
                    List <Field> array = new List <Field>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        if (item.ValueKind == JsonValueKind.Null)
                        {
                            array.Add(null);
                        }
                        else
                        {
                            array.Add(Field.DeserializeField(item));
                        }
                    }
                    fields = array;
                    continue;
                }
                if (property.NameEquals("scoringProfiles"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    List <ScoringProfile> array = new List <ScoringProfile>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        if (item.ValueKind == JsonValueKind.Null)
                        {
                            array.Add(null);
                        }
                        else
                        {
                            array.Add(ScoringProfile.DeserializeScoringProfile(item));
                        }
                    }
                    scoringProfiles = array;
                    continue;
                }
                if (property.NameEquals("defaultScoringProfile"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    defaultScoringProfile = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("corsOptions"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    corsOptions = CorsOptions.DeserializeCorsOptions(property.Value);
                    continue;
                }
                if (property.NameEquals("suggesters"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    List <Suggester> array = new List <Suggester>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        if (item.ValueKind == JsonValueKind.Null)
                        {
                            array.Add(null);
                        }
                        else
                        {
                            array.Add(Suggester.DeserializeSuggester(item));
                        }
                    }
                    suggesters = array;
                    continue;
                }
                if (property.NameEquals("analyzers"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    List <Analyzer> array = new List <Analyzer>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        if (item.ValueKind == JsonValueKind.Null)
                        {
                            array.Add(null);
                        }
                        else
                        {
                            array.Add(Analyzer.DeserializeAnalyzer(item));
                        }
                    }
                    analyzers = array;
                    continue;
                }
                if (property.NameEquals("tokenizers"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    List <Tokenizer> array = new List <Tokenizer>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        if (item.ValueKind == JsonValueKind.Null)
                        {
                            array.Add(null);
                        }
                        else
                        {
                            array.Add(Tokenizer.DeserializeTokenizer(item));
                        }
                    }
                    tokenizers = array;
                    continue;
                }
                if (property.NameEquals("tokenFilters"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    List <TokenFilter> array = new List <TokenFilter>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        if (item.ValueKind == JsonValueKind.Null)
                        {
                            array.Add(null);
                        }
                        else
                        {
                            array.Add(TokenFilter.DeserializeTokenFilter(item));
                        }
                    }
                    tokenFilters = array;
                    continue;
                }
                if (property.NameEquals("charFilters"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    List <CharFilter> array = new List <CharFilter>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        if (item.ValueKind == JsonValueKind.Null)
                        {
                            array.Add(null);
                        }
                        else
                        {
                            array.Add(CharFilter.DeserializeCharFilter(item));
                        }
                    }
                    charFilters = array;
                    continue;
                }
                if (property.NameEquals("encryptionKey"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    encryptionKey = EncryptionKey.DeserializeEncryptionKey(property.Value);
                    continue;
                }
                if (property.NameEquals("similarity"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    similarity = Similarity.DeserializeSimilarity(property.Value);
                    continue;
                }
                if (property.NameEquals("@odata.etag"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    odataEtag = property.Value.GetString();
                    continue;
                }
            }
            return(new Index(name, fields, scoringProfiles, defaultScoringProfile, corsOptions, suggesters, analyzers, tokenizers, tokenFilters, charFilters, encryptionKey, similarity, odataEtag));
        }