namespace Lattice.Core.DragDrop.Extensions; /// /// Методы расширения для DropInfo. /// public static class DropInfoExtensions { /// /// Проверяет, могут ли данные быть приведены к указанному типу. /// public static bool CanAccept(this Models.DropInfo dropInfo) where T : class { return dropInfo.Data is T; } /// /// Пытается получить данные как указанный тип. /// public static T? GetDataAs(this Models.DropInfo dropInfo) where T : class { return dropInfo.Data as T; } /// /// Получает данные как указанный тип или выбрасывает исключение. /// public static T GetRequiredDataAs(this Models.DropInfo dropInfo) where T : class { if (dropInfo.Data is not T data) { throw new InvalidCastException( $"Ожидался тип {typeof(T).Name}, но получен {dropInfo.Data?.GetType().Name ?? "null"}"); } return data; } /// /// Проверяет, содержится ли позиция в указанных границах. /// public static bool IsInBounds(this Models.DropInfo dropInfo, Geometry.Rect bounds) { return bounds.Contains(dropInfo.Position); } }