// Copyright Epic Games, Inc. All Rights Reserved.
using System;
using System.Collections.Generic;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace EpicGames.Slack
{
///
/// Abstract base class for all BlockKit elements to derive from.
///
[JsonConverter(typeof(ElementConverter))]
public abstract class Element
{
///
/// Type of the element
///
[JsonPropertyName("type"), JsonPropertyOrder(0)]
public string Type { get; set; }
///
/// Constructor
///
///
protected Element(string type)
{
Type = type;
}
}
///
/// Something that contains a list of elements. Used for extension methods.
///
public interface ISlackElementContainer
{
///
/// List of elements in this container
///
public List Elements { get; }
}
///
/// Polymorphic serializer for Block objects.
///
class ElementConverter : JsonConverter
{
public override Element? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
throw new NotImplementedException();
}
public override void Write(Utf8JsonWriter writer, Element value, JsonSerializerOptions options)
{
JsonSerializer.Serialize(writer, (object)value, value.GetType(), options);
}
}
}