public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { Block baseBlock = (Block)value; JObject block = new JObject(); block["type"] = baseBlock.Type; if (baseBlock.Block_ID != null) { block["block_id"] = baseBlock.Block_ID; } if (value is SectionBlock) { SectionBlock derivedBlock = (SectionBlock)value; if (derivedBlock.Fields != null) { block["fields"] = JArray.FromObject(derivedBlock.Fields); } if (derivedBlock.Accessory != null) { block["accessory"] = JObject.FromObject(derivedBlock.Accessory); } if (derivedBlock.Text != null) { block["text"] = JObject.FromObject(derivedBlock.Text); } } else if (value is ImageBlock) { ImageBlock derivedBlock = (ImageBlock)value; if (derivedBlock.ImageURL != null) { block["image_url"] = derivedBlock.ImageURL; } if (derivedBlock.AltText != null) { block["alt_text"] = derivedBlock.AltText; } if (derivedBlock.Title != null) { block["title"] = JObject.FromObject(derivedBlock.Title); } } else if (value is ActionBlock) { ActionBlock derivedBlock = (ActionBlock)value; if (derivedBlock.Elements != null) { block["elements"] = JArray.FromObject(derivedBlock.Elements); } } else if (value is ContextBlock) { ContextBlock derivedBlock = (ContextBlock)value; if (derivedBlock.Elements != null) { block["elements"] = JArray.FromObject(derivedBlock.Elements); } } block.WriteTo(writer); }
private static IBlock CreateSectionBlock(dynamic blockJson) { var block = new SectionBlock() { block_id = blockJson.block_id ?? null, text = new Text() { type = blockJson.text.type, text = blockJson.text.text, emoji = blockJson.text.emoji ?? null, verbatim = blockJson.text.verbatim ?? null }, fields = blockJson.fields ?? null, accessory = blockJson.accessory ?? null }; return(block); }