/// <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 ServiceDescription GetFromJsonProperties(JsonReader reader) { ServiceDescription 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 = StatefulServiceDescriptionConverter.GetFromJsonProperties(reader); } else if (propValue.Equals("Stateless", StringComparison.Ordinal)) { obj = StatelessServiceDescriptionConverter.GetFromJsonProperties(reader); } else { throw new InvalidOperationException("Unknown ServiceKind."); } return(obj); }
/// <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, ServiceDescription obj) { var kind = obj.ServiceKind; if (kind.Equals(ServiceKind.Stateful)) { StatefulServiceDescriptionConverter.Serialize(writer, (StatefulServiceDescription)obj); } else if (kind.Equals(ServiceKind.Stateless)) { StatelessServiceDescriptionConverter.Serialize(writer, (StatelessServiceDescription)obj); } else { throw new InvalidOperationException("Unknown ServiceKind."); } }