Exemplo n.º 1
0
        /// <summary>
        /// Gets the object from Json properties.
        /// </summary>
        /// <param name="reader">The <see cref="T: Newtonsoft.Json.JsonReader" /> to read from.</param>
        /// <returns>The object Value.</returns>
        internal static ServicePartitionInfo GetFromJsonProperties(JsonReader reader)
        {
            ServicePartitionInfo obj;
            var propName = reader.ReadPropertyName();

            if (!propName.Equals("ServiceKind", StringComparison.Ordinal))
            {
                throw new JsonReaderException($"Incorrect discriminator property name {propName}, Expected discriminator property name is ServiceKind.");
            }

            var propValue = reader.ReadValueAsString();

            if (propValue.Equals("Stateful", StringComparison.Ordinal))
            {
                obj = StatefulServicePartitionInfoConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("Stateless", StringComparison.Ordinal))
            {
                obj = StatelessServicePartitionInfoConverter.GetFromJsonProperties(reader);
            }
            else
            {
                throw new InvalidOperationException("Unknown ServiceKind.");
            }

            return(obj);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Serializes the object to JSON.
        /// </summary>
        /// <param name="writer">The <see cref="T: Newtonsoft.Json.JsonWriter" /> to write to.</param>
        /// <param name="obj">The object to serialize to JSON.</param>
        internal static void Serialize(JsonWriter writer, ServicePartitionInfo obj)
        {
            var kind = obj.ServiceKind;

            if (kind.Equals(ServiceKind.Stateful))
            {
                StatefulServicePartitionInfoConverter.Serialize(writer, (StatefulServicePartitionInfo)obj);
            }
            else if (kind.Equals(ServiceKind.Stateless))
            {
                StatelessServicePartitionInfoConverter.Serialize(writer, (StatelessServicePartitionInfo)obj);
            }
            else
            {
                throw new InvalidOperationException("Unknown ServiceKind.");
            }
        }