From 70be31b8f8a3c57c3a9556cfa93fe5d94a82b1d6 Mon Sep 17 00:00:00 2001 From: Andy Butland Date: Mon, 24 Feb 2025 13:27:04 +0100 Subject: [PATCH] Added obsoletion methods for extension methods to be removed in Umbraco 16 (#18394) * Added obsoletion methods for extension methods to be removed in Umbraco 16. * Updated obsolete messages to reference Umbraco 17 * Fix typo --------- Co-authored-by: mole --- .../Extensions/AssemblyExtensions.cs | 2 ++ .../Extensions/CollectionExtensions.cs | 2 +- .../Extensions/DataTableExtensions.cs | 3 +++ .../Extensions/DelegateExtensions.cs | 2 ++ src/Umbraco.Core/Extensions/EnumExtensions.cs | 3 ++- .../Extensions/ExpressionExtensions.cs | 25 ------------------- .../Extensions/KeyValuePairExtensions.cs | 1 + .../NameValueCollectionExtensions.cs | 3 +++ .../Extensions/ObjectExtensions.cs | 4 +++ .../Extensions/PublishedContentExtensions.cs | 2 ++ .../Extensions/ThreadExtensions.cs | 1 + .../FriendlyPublishedContentExtensions.cs | 1 + 12 files changed, 22 insertions(+), 27 deletions(-) delete mode 100644 src/Umbraco.Core/Extensions/ExpressionExtensions.cs diff --git a/src/Umbraco.Core/Extensions/AssemblyExtensions.cs b/src/Umbraco.Core/Extensions/AssemblyExtensions.cs index b7cf65c414..488dc38c3c 100644 --- a/src/Umbraco.Core/Extensions/AssemblyExtensions.cs +++ b/src/Umbraco.Core/Extensions/AssemblyExtensions.cs @@ -47,6 +47,7 @@ public static class AssemblyExtensions /// /// /// + [Obsolete("This extension method is no longer used and will be removed in Umbraco 17.")] public static FileInfo GetAssemblyFile(this Assembly assembly) { var codeBase = assembly.Location; @@ -94,6 +95,7 @@ public static class AssemblyExtensions /// /// /// + [Obsolete("This extension method is no longer used and will be removed in Umbraco 17.")] public static FileInfo? GetAssemblyFile(this AssemblyName assemblyName) { var codeBase = assemblyName.CodeBase; diff --git a/src/Umbraco.Core/Extensions/CollectionExtensions.cs b/src/Umbraco.Core/Extensions/CollectionExtensions.cs index fd2f976d50..6e8903bf0f 100644 --- a/src/Umbraco.Core/Extensions/CollectionExtensions.cs +++ b/src/Umbraco.Core/Extensions/CollectionExtensions.cs @@ -2,7 +2,7 @@ namespace Umbraco.Cms.Core.Extensions; public static class CollectionExtensions { - // Easiest way to return a collection with 1 item, probably not the most performant + [Obsolete("Please replace uses of this extension method with collection expression. This method will be removed in Umbraco 17.")] public static ICollection ToSingleItemCollection(this T item) => new T[] { item }; } diff --git a/src/Umbraco.Core/Extensions/DataTableExtensions.cs b/src/Umbraco.Core/Extensions/DataTableExtensions.cs index 10fa51deaf..557a856472 100644 --- a/src/Umbraco.Core/Extensions/DataTableExtensions.cs +++ b/src/Umbraco.Core/Extensions/DataTableExtensions.cs @@ -21,6 +21,7 @@ public static class DataTableExtensions /// This has been migrated from the Node class and uses proper locking now. It is now used by the Node class and the /// DynamicPublishedContent extensions for legacy reasons. /// + [Obsolete("This no longer has a use in Umbraco and so will be removed in Umbraco 17.")] public static DataTable GenerateDataTable( string tableAlias, Func>> getHeaders, @@ -60,6 +61,7 @@ public static class DataTableExtensions /// /// This is for legacy code, I didn't want to go creating custom classes for these /// + [Obsolete("This no longer has a use in Umbraco and so will be removed in Umbraco 17.")] public static List>, IEnumerable>>> CreateTableData() => new List>, IEnumerable>>>(); @@ -73,6 +75,7 @@ public static class DataTableExtensions /// /// This is for legacy code, I didn't want to go creating custom classes for these /// + [Obsolete("This no longer has a use in Umbraco and so will be removed in Umbraco 17.")] public static void AddRowData( List>, IEnumerable>>> rowData, IEnumerable> standardVals, diff --git a/src/Umbraco.Core/Extensions/DelegateExtensions.cs b/src/Umbraco.Core/Extensions/DelegateExtensions.cs index 621ef46438..4528d9f0b8 100644 --- a/src/Umbraco.Core/Extensions/DelegateExtensions.cs +++ b/src/Umbraco.Core/Extensions/DelegateExtensions.cs @@ -8,6 +8,7 @@ namespace Umbraco.Extensions; public static class DelegateExtensions { + [Obsolete("This method is no longer used in Umbraco. The method will be removed in Umbraco 17.")] public static Attempt RetryUntilSuccessOrTimeout(this Func> task, TimeSpan timeout, TimeSpan pause) { if (pause.TotalMilliseconds < 0) @@ -31,6 +32,7 @@ public static class DelegateExtensions return Attempt.Fail(); } + [Obsolete("This method is no longer used in Umbraco. The method will be removed in Umbraco 17.")] public static Attempt RetryUntilSuccessOrMaxAttempts(this Func> task, int totalAttempts, TimeSpan pause) { if (pause.TotalMilliseconds < 0) diff --git a/src/Umbraco.Core/Extensions/EnumExtensions.cs b/src/Umbraco.Core/Extensions/EnumExtensions.cs index 4d07c1d382..be31c9e76c 100644 --- a/src/Umbraco.Core/Extensions/EnumExtensions.cs +++ b/src/Umbraco.Core/Extensions/EnumExtensions.cs @@ -1,4 +1,4 @@ -// Copyright (c) Umbraco. +// Copyright (c) Umbraco. // See LICENSE for more details. namespace Umbraco.Extensions @@ -17,6 +17,7 @@ namespace Umbraco.Extensions /// /// true if any of the flags/bits are set within the enum value; otherwise, false. /// + [Obsolete("This method is no longer used in Umbraco. The method will be removed in Umbraco 17.")] public static bool HasFlagAny(this T value, T flags) where T : Enum { diff --git a/src/Umbraco.Core/Extensions/ExpressionExtensions.cs b/src/Umbraco.Core/Extensions/ExpressionExtensions.cs deleted file mode 100644 index 12476c9506..0000000000 --- a/src/Umbraco.Core/Extensions/ExpressionExtensions.cs +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) Umbraco. -// See LICENSE for more details. - -using System.Linq.Expressions; - -namespace Umbraco.Cms.Core; - -internal static class ExpressionExtensions -{ - public static Expression> True() => f => true; - - public static Expression> False() => f => false; - - public static Expression> Or(this Expression> left, Expression> right) - { - InvocationExpression invokedExpr = Expression.Invoke(right, left.Parameters); - return Expression.Lambda>(Expression.OrElse(left.Body, invokedExpr), left.Parameters); - } - - public static Expression> And(this Expression> left, Expression> right) - { - InvocationExpression invokedExpr = Expression.Invoke(right, left.Parameters); - return Expression.Lambda>(Expression.AndAlso(left.Body, invokedExpr), left.Parameters); - } -} diff --git a/src/Umbraco.Core/Extensions/KeyValuePairExtensions.cs b/src/Umbraco.Core/Extensions/KeyValuePairExtensions.cs index 7189c4cc15..760700a624 100644 --- a/src/Umbraco.Core/Extensions/KeyValuePairExtensions.cs +++ b/src/Umbraco.Core/Extensions/KeyValuePairExtensions.cs @@ -12,6 +12,7 @@ public static class KeyValuePairExtensions /// Implements key/value pair deconstruction. /// /// Allows for foreach ((var k, var v) in ...). + [Obsolete("Please replace uses of this extension method with native language features. This method will be removed in Umbraco 17.")] public static void Deconstruct(this KeyValuePair kvp, out TKey key, out TValue value) { key = kvp.Key; diff --git a/src/Umbraco.Core/Extensions/NameValueCollectionExtensions.cs b/src/Umbraco.Core/Extensions/NameValueCollectionExtensions.cs index f8fdcdc83f..e5e780ccbc 100644 --- a/src/Umbraco.Core/Extensions/NameValueCollectionExtensions.cs +++ b/src/Umbraco.Core/Extensions/NameValueCollectionExtensions.cs @@ -8,6 +8,7 @@ namespace Umbraco.Extensions; public static class NameValueCollectionExtensions { + [Obsolete("This method is no longer used in Umbraco. The method will be removed in Umbraco 17.")] public static IEnumerable> AsEnumerable(this NameValueCollection nvc) { foreach (var key in nvc.AllKeys) @@ -16,9 +17,11 @@ public static class NameValueCollectionExtensions } } + [Obsolete("This method is no longer used in Umbraco. The method will be removed in Umbraco 17.")] public static bool ContainsKey(this NameValueCollection collection, string key) => collection.Keys.Cast().Any(k => (string)k == key); + [Obsolete("This method is no longer used in Umbraco. The method will be removed in Umbraco 17.")] public static T? GetValue(this NameValueCollection collection, string key, T defaultIfNotFound) { if (collection.ContainsKey(key) == false) diff --git a/src/Umbraco.Core/Extensions/ObjectExtensions.cs b/src/Umbraco.Core/Extensions/ObjectExtensions.cs index 50fe788da0..c720c85ecc 100644 --- a/src/Umbraco.Core/Extensions/ObjectExtensions.cs +++ b/src/Umbraco.Core/Extensions/ObjectExtensions.cs @@ -44,6 +44,7 @@ public static class ObjectExtensions /// Disposes the object if it implements . /// /// The object. + [Obsolete("Please replace uses of this extension method with (input as IDisposable)?.Dispose(). This extension method will be removed in Umbraco 17.")] public static void DisposeIfDisposable(this object input) { if (input is IDisposable disposable) @@ -66,6 +67,7 @@ public static class ObjectExtensions /// /// The input. /// + [Obsolete("This extension method is not longer used and will be removed in Umbraco 17.")] public static T? SafeCast(this object input) { if (ReferenceEquals(null, input) || ReferenceEquals(default(T), input)) @@ -353,6 +355,7 @@ public static class ObjectExtensions /// /// /// + [Obsolete("This method is no longer used in Umbraco. The method will be removed in Umbraco 17.")] public static IDictionary? ToDictionary( this T o, params Expression>[] ignoreProperties) => o?.ToDictionary(ignoreProperties @@ -532,6 +535,7 @@ public static class ObjectExtensions /// /// Properties to ignore /// + [Obsolete("Use of this can be replaced with RouteValueDictionary or HtmlHelper.AnonymousObjectToHtmlAttributes(). The method will be removed in Umbraco 17.")] public static IDictionary ToDictionary(this object o, params string[] ignoreProperties) { if (o != null) diff --git a/src/Umbraco.Core/Extensions/PublishedContentExtensions.cs b/src/Umbraco.Core/Extensions/PublishedContentExtensions.cs index d77634f909..a2204c9fb5 100644 --- a/src/Umbraco.Core/Extensions/PublishedContentExtensions.cs +++ b/src/Umbraco.Core/Extensions/PublishedContentExtensions.cs @@ -3298,6 +3298,7 @@ public static class PublishedContentExtensions /// /// /// The children of the content. + [Obsolete("This method is no longer used in Umbraco. The method will be removed in Umbraco 17.")] public static DataTable ChildrenAsTable( this IPublishedContent content, IVariationContextAccessor variationContextAccessor, @@ -3640,6 +3641,7 @@ public static class PublishedContentExtensions where T : class, IPublishedContent => Children(content, variationContextAccessor, StaticServiceProvider.Instance.GetRequiredService(), culture); + [Obsolete("This method is no longer used in Umbraco. The method will be removed in Umbraco 17.")] public static DataTable ChildrenAsTable( this IPublishedContent content, IVariationContextAccessor variationContextAccessor, diff --git a/src/Umbraco.Core/Extensions/ThreadExtensions.cs b/src/Umbraco.Core/Extensions/ThreadExtensions.cs index b1e5515b88..c365038071 100644 --- a/src/Umbraco.Core/Extensions/ThreadExtensions.cs +++ b/src/Umbraco.Core/Extensions/ThreadExtensions.cs @@ -7,6 +7,7 @@ namespace Umbraco.Extensions; public static class ThreadExtensions { + [Obsolete("This method is no longer used in Umbraco. The method will be removed in Umbraco 17.")] public static void SanitizeThreadCulture(this Thread thread) { // get the current culture diff --git a/src/Umbraco.Web.Common/Extensions/FriendlyPublishedContentExtensions.cs b/src/Umbraco.Web.Common/Extensions/FriendlyPublishedContentExtensions.cs index 38ba31245b..31171cc880 100644 --- a/src/Umbraco.Web.Common/Extensions/FriendlyPublishedContentExtensions.cs +++ b/src/Umbraco.Web.Common/Extensions/FriendlyPublishedContentExtensions.cs @@ -669,6 +669,7 @@ public static class FriendlyPublishedContentExtensions /// null) /// /// The children of the content. + [Obsolete("This method is no longer used in Umbraco. The method will be removed in Umbraco 17.")] public static DataTable ChildrenAsTable(this IPublishedContent content, string contentTypeAliasFilter = "", string? culture = null) => content.ChildrenAsTable(