You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

ModelMap.cs 799 B

123456789101112131415161718192021222324
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. namespace Discord.Serialization
  5. {
  6. public class ModelMap<TModel>
  7. where TModel : class, new()
  8. {
  9. private BufferDictionary<PropertyMap> _dictionary;
  10. public PropertyMap[] Properties { get; }
  11. public ModelMap(List<PropertyMap> properties)
  12. {
  13. Properties = properties.ToArray();
  14. _dictionary = new BufferDictionary<PropertyMap>(properties.ToDictionary(x => x.Utf8Key));
  15. }
  16. public bool TryGetProperty(ReadOnlyBuffer<byte> key, out PropertyMap value)
  17. => _dictionary.TryGetValue(key, out value);
  18. public bool TryGetProperty(ReadOnlySpan<byte> key, out PropertyMap value)
  19. => _dictionary.TryGetValue(key, out value);
  20. }
  21. }