/// <summary> /// Deserializes an <see cref="WitnessCondition"/> object from a <see cref="MemoryReader"/>. /// </summary> /// <param name="reader">The <see cref="MemoryReader"/> for reading data.</param> /// <param name="maxNestDepth">The maximum nesting depth allowed during deserialization.</param> /// <returns>The deserialized <see cref="WitnessCondition"/>.</returns> public static WitnessCondition DeserializeFrom(ref MemoryReader reader, int maxNestDepth) { WitnessConditionType type = (WitnessConditionType)reader.ReadByte(); if (ReflectionCache <WitnessConditionType> .CreateInstance(type) is not WitnessCondition condition) { throw new FormatException(); } condition.DeserializeWithoutType(ref reader, maxNestDepth); return(condition); }
/// <summary> /// Converts the <see cref="WitnessCondition"/> from a JSON object. /// </summary> /// <param name="json">The <see cref="WitnessCondition"/> represented by a JSON object.</param> /// <returns>The converted <see cref="WitnessCondition"/>.</returns> public static WitnessCondition FromJson(JObject json) { WitnessConditionType type = Enum.Parse <WitnessConditionType>(json["type"].GetString()); if (ReflectionCache <WitnessConditionType> .CreateInstance(type) is not WitnessCondition condition) { throw new FormatException("Invalid WitnessConditionType."); } condition.ParseJson(json); return(condition); }