Repository: AvaloniaUI/Avalonia
File: src/Windows/Avalonia.Win32/ClipboardFormatRegistry.cs (C#)

Code before:
﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using Avalonia.Input;
using Avalonia.Media.Imaging;
using Avalonia.Utilities;
using Avalonia.Win32.Interop;

namespace Avalonia.Win32
{
    internal static class ClipboardFormatRegistry
    {
        private const int MaxFormatNameLength = 260;
        private const string AppPrefix = "avn-app-fmt:";
        public const string PngFormatMimeType = "image/png";
        public const string BitmapFormat = "CF_BITMAP";
        public const string DibFormat = "CF_DIB";
        private static readonly List<(DataFormat Format, ushort Id)> s_formats = [];

        public static DataFormat PngSystemDataFormat = DataFormat.FromSystemName<Bitmap>("PNG" , AppPrefix);
        public static DataFormat PngDataFormat = DataFormat.FromSystemName<Bitmap>(PngFormatMimeType , AppPrefix);
        public static DataFormat HBitmapDataFormat = DataFormat.FromSystemName<Bitmap>(BitmapFormat, AppPrefix);
        public static DataFormat DibDataFormat = DataFormat.FromSystemName<Bitmap>(DibFormat, AppPrefix);

        public static DataFormat[] ImageFormats = [PngDataFormat, PngSystemDataFormat, DibDataFormat, HBitmapDataFormat]; 

        static ClipboardFormatRegistry()
        {
            AddDataFormat(DataFormat.Text, (ushort)UnmanagedMethods.ClipboardFormat.CF_UNICODETEXT);
            AddDataFormat(DataFormat.Text, (ushort)UnmanagedMethods.ClipboardFormat.CF_TEXT);
            AddDataFormat(DataFormat.File, (ushort)UnmanagedMethods.ClipboardFormat.CF_HDROP);
            AddDataFormat(DibDataFormat, (ushort)UnmanagedMethods.ClipboardFormat.CF_DIB);
            AddDataFormat(HBitmapDataFormat, (ushort)UnmanagedMethods.ClipboardFormat.CF_BITMAP);
        }

        private static void AddDataFormat(DataFormat format, ushort id)
            => s_formats.Add((format, id));

        private static string GetFormatSystemName(ushort id)
        {
            var buffer = StringBuilderCache.Acquire(MaxFormatNameLength);
            if (UnmanagedMethods.GetClipboardFormatName(id, buffer, buffer.Capacity) > 0)
                return StringBuilderCache.GetStringAndRelease(buffer);
            if (Enum.IsDefined(typeof(UnmanagedMethods.ClipboardFormat), (int)id))
                return Enum.GetName(typeof(UnmanagedMethods.ClipboardFormat), (int)id)!;
            return $"Unknown_Format_{id}";

Review comment (suggestion):
The names are not too helpful, would prefer `PngDataFormat` for PNG and `PngMimeDataFormat` for image/png.

Code after:
﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using Avalonia.Input;
using Avalonia.Media.Imaging;
using Avalonia.Utilities;
using Avalonia.Win32.Interop;

namespace Avalonia.Win32
{
    internal static class ClipboardFormatRegistry
    {
        private const int MaxFormatNameLength = 260;
        private const string AppPrefix = "avn-app-fmt:";
        public const string PngFormatMimeType = "image/png";
        public const string PngFormatSystemType = "PNG";
        public const string BitmapFormat = "CF_BITMAP";
        public const string DibFormat = "CF_DIB";
        public const string DibV5Format = "CF_DIBV5";
        private static readonly List<(DataFormat Format, ushort Id)> s_formats = [];

        public static DataFormat PngSystemDataFormat = DataFormat.FromSystemName<Bitmap>(PngFormatSystemType, AppPrefix);
        public static DataFormat PngMimeDataFormat = DataFormat.FromSystemName<Bitmap>(PngFormatMimeType, AppPrefix);
        public static DataFormat HBitmapDataFormat = DataFormat.FromSystemName<Bitmap>(BitmapFormat, AppPrefix);
        public static DataFormat DibDataFormat = DataFormat.FromSystemName<Bitmap>(DibFormat, AppPrefix);
        public static DataFormat DibV5DataFormat = DataFormat.FromSystemName<Bitmap>(DibV5Format, AppPrefix);

        public static DataFormat[] ImageFormats = [PngMimeDataFormat, PngSystemDataFormat, DibDataFormat, DibV5DataFormat, HBitmapDataFormat];

        static ClipboardFormatRegistry()
        {
            AddDataFormat(DataFormat.Text, (ushort)UnmanagedMethods.ClipboardFormat.CF_UNICODETEXT);
            AddDataFormat(DataFormat.Text, (ushort)UnmanagedMethods.ClipboardFormat.CF_TEXT);
            AddDataFormat(DataFormat.File, (ushort)UnmanagedMethods.ClipboardFormat.CF_HDROP);
            AddDataFormat(DibDataFormat, (ushort)UnmanagedMethods.ClipboardFormat.CF_DIB);
            AddDataFormat(DibV5DataFormat, (ushort)UnmanagedMethods.ClipboardFormat.CF_DIBV5);
            AddDataFormat(HBitmapDataFormat, (ushort)UnmanagedMethods.ClipboardFormat.CF_BITMAP);
        }

        private static void AddDataFormat(DataFormat format, ushort id)
            => s_formats.Add((format, id));

        private static string GetFormatSystemName(ushort id)
        {
            var buffer = StringBuilderCache.Acquire(MaxFormatNameLength);
            if (UnmanagedMethods.GetClipboardFormatName(id, buffer, buffer.Capacity) > 0)