Exemple #1
0
        public string GetMap(string key, string context = null)
        {
            if (string.IsNullOrWhiteSpace(key))
            {
                return(null);
            }

            var searchKey = new TextMapKey(key,
                                           string.IsNullOrWhiteSpace(context) ? TextMapKey.__UnspecifiedContext : context);

            if (_maps.TryGetValue(searchKey, out var value))
            {
                return(value);
            }

            return(key);
        }
Exemple #2
0
        public TextMapService(string json)
        {
            if (string.IsNullOrWhiteSpace(json))
            {
                return;
            }

            var entries = JsonSerializer.Deserialize <List <TextMapEntry> >
                              (json, new JsonSerializerOptions {
                PropertyNameCaseInsensitive = true
            })
                          .OrderByDescending(x => x.Context).ThenBy(x => x.Key)
                          .ToList();

            foreach (var entry in entries)
            {
                var key = new TextMapKey(entry);
                if (!_maps.ContainsKey(key))
                {
                    _maps.Add(key, entry.Value);
                }
            }
        }