public void RemoveKey(IDictionaryKey key)
        {
            if (innerDictionary.ContainsKey(key))
            {
                SLOT slot = innerDictionary[key];
                innerDictionary.Remove(key);

                ILinkSlot ls = slot as ILinkSlot;
                if (ls != null)
                {
                    ls.isDeleted = true;
                    if (ls.preSlot != null)
                    {
                        ls.preSlot.nextSlot = ls.nextSlot;

                        if (ls.nextSlot != null)
                        {
                            ls.nextSlot.preSlot = ls.preSlot;
                        }

                        ls.preSlot = null;
                    }
                    else
                    {
                        if (ls.nextSlot != null)
                        {
                            ls.nextSlot.preSlot = null;
                        }
                    }
                }
            }
        }
 public void createKeyValue(IDictionaryKey key,ILinkSlot value)
 {
     if (!isContainsKey(key))
     {
         innerDictionary.Add(key,(SLOT)value);
         if (rootSlot == null)
         {
             rootSlot = value;
         }
         else
         {
             rootSlot.preSlot = value;
             value.nextSlot   = rootSlot;
             rootSlot         = value;
         }
     }
 }
Beispiel #3
0
        public override void Write(
            Utf8JsonWriter writer,
            Dictionary <TKey, TValue> dictionary,
            JsonSerializerOptions options)
        {
            writer.WriteStartObject();

            foreach (var item in dictionary)
            {
                if (item.Key is null)
                {
                    throw new SerializationException("Null key");
                }

                var propertyName = item.Key switch
                {
                    string stringKey => stringKey,
                    IDictionaryKey key => key.Key,
                    _ => throw new SerializationException("Must implement IDictionaryKey")
                };

                writer.WritePropertyName
                    (options.PropertyNamingPolicy?.ConvertName(propertyName) ?? propertyName);

                if (item.Value is null)
                {
                    writer.WriteNullValue();
                }
                else if (_valueConverter != null)
                {
                    _valueConverter.Write(writer, item.Value, options);
                }
                else
                {
                    JsonSerializer.Serialize(writer, item.Value, item.Value.GetType(), options);
                }
            }

            writer.WriteEndObject();
        }
    }
 public SLOT getValue(IDictionaryKey key)
 {
     return(innerDictionary[key]);
 }
 public bool isContainsKey(IDictionaryKey value)
 {
     return(innerDictionary.ContainsKey(value));
 }