using System.Text;
using System.Threading.Tasks;
using Artemis.Core;
using Avalonia.Input.Platform;
namespace Artemis.UI.Shared.Extensions;
///
/// Provides extension methods for Avalonia's type.
///
public static class ClipboardExtensions
{
///
/// Retrieves clipboard JSON data representing and deserializes it into an instance of
/// .
///
/// The clipboard to retrieve the data off.
/// The data format to retrieve data for.
/// The type of data to retrieve
///
/// The resulting value or if the clipboard did not contain data for the provided ;
/// .
///
public static async Task GetJsonAsync(this IClipboard clipboard, string format)
{
byte[]? bytes = (byte[]?) await clipboard.GetDataAsync(format);
return bytes == null ? default : CoreJson.DeserializeObject(Encoding.Unicode.GetString(bytes), true);
}
}