diff --git a/Avalonia/Input/DataObjectExtensions.cs b/Avalonia/Input/DataObjectExtensions.cs index 8e39b2e..9706e5d 100644 --- a/Avalonia/Input/DataObjectExtensions.cs +++ b/Avalonia/Input/DataObjectExtensions.cs @@ -31,15 +31,22 @@ public static class DataObjectExtensions /// True if at least one file name is contained in . public static bool HasFileNames(this IDataObject data) => Global.RunOrDefault(() => { - return data.GetFiles()?.Let(it => + try { - foreach (var item in it) + return data.GetFiles()?.Let(it => { - if (!string.IsNullOrEmpty(item.TryGetLocalPath())) - return true; - } + foreach (var item in it) + { + if (!string.IsNullOrEmpty(item.TryGetLocalPath())) + return true; + } + return false; + }) ?? false; + } + catch + { return false; - }) ?? false; + } }); @@ -53,11 +60,18 @@ public static bool HasFileNames(this IDataObject data) => Global.RunOrDefault(() /// True if data got successfully. public static bool TryGetData(this IDataObject dataObject, string format, out T? data) where T : class { - var rawData = dataObject.Get(format); - if (rawData is T dataT) + try { - data = dataT; - return true; + var rawData = dataObject.Get(format); + if (rawData is T dataT) + { + data = dataT; + return true; + } + } + catch + { + // ignored } data = default; return false; @@ -105,11 +119,18 @@ public static bool TryGetSingleFileName(this IDataObject data, out string? fileN /// True if value got successfully. public static bool TryGetValue(this IDataObject dataObject, string format, out T value) where T : struct { - var rawData = dataObject.Get(format); - if (rawData is T targetValue) + try + { + var rawData = dataObject.Get(format); + if (rawData is T targetValue) + { + value = targetValue; + return true; + } + } + catch { - value = targetValue; - return true; + // ignored } value = default; return false;