public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { IClusterRerouteCommand command = null; var o = JObject.Load(reader); var child = o.Children <JProperty>().FirstOrDefault(); if (child == null) { return(null); } var v = child.Children <JObject>().FirstOrDefault(); if (v == null) { return(null); } switch (child.Name) { case "allocate": command = v.ToObject <AllocateClusterRerouteCommand>(ElasticContractResolver.Empty); break; case "move": command = v.ToObject <MoveClusterRerouteCommand>(ElasticContractResolver.Empty); break; case "cancel": command = v.ToObject <CancelClusterRerouteCommand>(ElasticContractResolver.Empty); break; } return(command); }
private void AddCommand(IClusterRerouteCommand rerouteCommand) { rerouteCommand.ThrowIfNull("rerouteCommand"); if (this.Self.Commands == null) { this.Self.Commands = new List <IClusterRerouteCommand>(); } this.Self.Commands.Add(rerouteCommand); }
private ClusterRerouteDescriptor AddCommand(IClusterRerouteCommand rerouteCommand) => Assign(rerouteCommand, (a, v) => a.Commands?.AddIfNotNull(v));
private ClusterRerouteDescriptor AddCommand(IClusterRerouteCommand rerouteCommand) => Assign(a => a.Commands?.AddIfNotNull(rerouteCommand));