C#C
C#2y ago
SWEETPONY

✅ How to serialize IEnumerable<T> to json?

I have following:
public IReadOnlyList<MessageQueueConsumeResultHeader>? Headers { get; init; }

public abstract class MessageQueueConsumeResultHeader
  {
    public abstract string Key { get; }

    public abstract byte[] GetValueBytes();

    public override string ToString()
    {
      return this.Key + " (" + string.Join<byte>(",", (IEnumerable<byte>) this.GetValueBytes()) + ")";
    }
  }


and I want to get following:

"
{
"Key": "GetValueBytes()",
...
}
"

how can I do it?
Was this page helpful?