Example #1
0
        public T Read(ref Utf8JsonReader reader, JsonSerializerOptions options)
        {
            ReadOnlySpan <byte> name = reader.GetRawString();

            if (!_names2Values.TryGetValue(name, out T key))
            {
                throw new JsonException();
            }

            return(key);
        }
Example #2
0
        public T ReadString(ref CborReader reader)
        {
            ReadOnlySpan <byte> rawName = reader.ReadRawString();

            if (!names2Values.TryGetValue(rawName, out T enumValue))
            {
                throw reader.BuildException($"Unknown name {Encoding.ASCII.GetString(rawName)} for enum {typeof(T).Name}");
            }

            return(enumValue);
        }
        public void AddTryGet(string values)
        {
            ByteBufferDictionary <string> binaryTree = new ByteBufferDictionary <string>();

            string[] valuesArray = values.Split(',');

            foreach (string value in valuesArray)
            {
                binaryTree.Add(value.AsBinarySpan(), value);
            }

            foreach (string value in valuesArray)
            {
                bool success = binaryTree.TryGetValue(value.AsBinarySpan(), out string actualValue);
                Assert.True(success);
                Assert.Equal(value, actualValue);
            }
        }