< Summary

Class:Microsoft.Azure.Search.Serialization.SuggestResultConverter`1
Assembly:Microsoft.Azure.Search.Data
File(s):C:\Git\azure-sdk-for-net\sdk\search\Microsoft.Azure.Search.Data\src\Customizations\Serialization\SuggestResultConverter.cs
Covered lines:6
Uncovered lines:2
Coverable lines:8
Total lines:39
Line coverage:75% (6 of 8)
Covered branches:0
Total branches:0

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
get_CanRead()-100%100%
get_CanWrite()-0%100%
CanConvert(...)-100%100%
ReadJson(...)-100%100%
WriteJson(...)-0%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\search\Microsoft.Azure.Search.Data\src\Customizations\Serialization\SuggestResultConverter.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License. See License.txt in the project root for
 3// license information.
 4
 5namespace Microsoft.Azure.Search.Serialization
 6{
 7    using System;
 8    using System.Reflection;
 9    using Microsoft.Azure.Search.Models;
 10    using Newtonsoft.Json;
 11    using Newtonsoft.Json.Linq;
 12
 13    /// <summary>
 14    /// Deserializes SuggestResult instances from OData-compliant JSON.
 15    /// </summary>
 16    /// <typeparam name="T">
 17    /// The CLR type that maps to the index schema. Instances of this type can be stored as documents in the index.
 18    /// </typeparam>
 19    internal class SuggestResultConverter<T> : JsonConverter
 20    {
 10821        public override bool CanRead => true;
 22
 023        public override bool CanWrite => false;
 24
 25        public override bool CanConvert(Type objectType) =>
 16722426            typeof(SuggestResult<T>).GetTypeInfo().IsAssignableFrom(objectType.GetTypeInfo());
 27
 28        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer seriali
 29        {
 10830            JObject propertyBag = serializer.Deserialize<JObject>(reader);
 10831            JToken text = propertyBag["@search.text"];
 32
 10833            var docReader = new JTokenReader(propertyBag);
 10834            return new SuggestResult<T>(document: serializer.Deserialize<T>(docReader), text: text.Value<string>());
 35        }
 36
 037        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) => throw new NotImple
 38    }
 39}