1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00
Artemis/src/Artemis.UI.Shared/Extensions/ClipboardExtensions.cs
Robert dd40bdd544 Profiles - Added module activation requirements
Editor - Refactored tools and selected keyframes management
Timeline - Added keyframe duplicating, copying and pasting
Windows UI - Added logging of fatal exceptions
2022-06-05 18:57:42 +02:00

29 lines
1.2 KiB
C#

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