/// <summary> /// Converts the method from a JSON object. /// </summary> /// <param name="json">The method represented by a JSON object.</param> /// <returns>The converted method.</returns> public new static ContractMethodDescriptor FromJson(JObject json) { ContractMethodDescriptor descriptor = new() { Name = json["name"].GetString(), Parameters = ((JArray)json["parameters"]).Select(u => ContractParameterDefinition.FromJson(u)).ToArray(), ReturnType = Enum.Parse <ContractParameterType>(json["returntype"].GetString()), Offset = json["offset"].GetInt32(), Safe = json["safe"].GetBoolean() }; if (string.IsNullOrEmpty(descriptor.Name)) { throw new FormatException(); } _ = descriptor.Parameters.ToDictionary(p => p.Name); if (!Enum.IsDefined(descriptor.ReturnType)) { throw new FormatException(); } if (descriptor.Offset < 0) { throw new FormatException(); } return(descriptor); }
/// <summary> /// Converts the event from a JSON object. /// </summary> /// <param name="json">The event represented by a JSON object.</param> /// <returns>The converted event.</returns> public static ContractEventDescriptor FromJson(JObject json) { ContractEventDescriptor descriptor = new() { Name = json["name"].GetString(), Parameters = ((JArray)json["parameters"]).Select(u => ContractParameterDefinition.FromJson(u)).ToArray(), }; if (string.IsNullOrEmpty(descriptor.Name)) { throw new FormatException(); } _ = descriptor.Parameters.ToDictionary(p => p.Name); return(descriptor); }