From 8904cbdef84e6743e0fc443af3a59ec61d273229 Mon Sep 17 00:00:00 2001 From: David Date: Thu, 3 Oct 2024 12:58:04 -0400 Subject: [PATCH] fix: Fix default immutable array (+ docs + namespace update) --- .../Extensibility/AddIns.cs | 6 +++--- .../Extensibility/AddInsExtensions.cs | 2 +- .../AttributeDataExtensions.cs | 15 ++++++++++++++- .../ServiceAttribute.cs | 2 +- .../ServiceCollectionServiceExtensions.cs | 3 ++- 5 files changed, 21 insertions(+), 7 deletions(-) rename src/Uno.UI.RemoteControl.Host/Extensibility/{Uno.Extensions.DependencyInjection => Uno.Utils.DependencyInjection}/AttributeDataExtensions.cs (65%) rename src/Uno.UI.RemoteControl.Host/Extensibility/{Uno.Extensions.DependencyInjection => Uno.Utils.DependencyInjection}/ServiceAttribute.cs (97%) rename src/Uno.UI.RemoteControl.Host/Extensibility/{Uno.Extensions.DependencyInjection => Uno.Utils.DependencyInjection}/ServiceCollectionServiceExtensions.cs (97%) diff --git a/src/Uno.UI.RemoteControl.Host/Extensibility/AddIns.cs b/src/Uno.UI.RemoteControl.Host/Extensibility/AddIns.cs index 0c80c868ede0..9d170b757ef2 100644 --- a/src/Uno.UI.RemoteControl.Host/Extensibility/AddIns.cs +++ b/src/Uno.UI.RemoteControl.Host/Extensibility/AddIns.cs @@ -11,7 +11,7 @@ namespace Uno.UI.RemoteControl.Host.Extensibility; public class AddIns { - private static ILogger _log = typeof(AddIns).Log(); + private static readonly ILogger _log = typeof(AddIns).Log(); public static IImmutableList Discover(string solutionFile) { @@ -30,7 +30,7 @@ public static IImmutableList Discover(string solutionFile) _log.Log(LogLevel.Warning, new Exception(result.error), $"Failed to get target frameworks of solution '{solutionFile}' (cf. inner exception for details)."); } - return new ImmutableArray(); + return ImmutableArray.Empty; } @@ -64,7 +64,7 @@ public static IImmutableList Discover(string solutionFile) _log.Log(LogLevel.Information, $"Didn't find any add-ins for solution '{solutionFile}'."); } - return ImmutableList.Empty; + return ImmutableArray.Empty; } private static IEnumerable GetConfigurationValue(string msbuildResult, string nodeName) diff --git a/src/Uno.UI.RemoteControl.Host/Extensibility/AddInsExtensions.cs b/src/Uno.UI.RemoteControl.Host/Extensibility/AddInsExtensions.cs index 461340b9480e..80491025e1b3 100644 --- a/src/Uno.UI.RemoteControl.Host/Extensibility/AddInsExtensions.cs +++ b/src/Uno.UI.RemoteControl.Host/Extensibility/AddInsExtensions.cs @@ -1,7 +1,7 @@ using System; using System.Linq; using Microsoft.AspNetCore.Hosting; -using Uno.Extensions.DependencyInjection; +using Uno.Utils.DependencyInjection; using Uno.UI.RemoteControl.Helpers; namespace Uno.UI.RemoteControl.Host.Extensibility; diff --git a/src/Uno.UI.RemoteControl.Host/Extensibility/Uno.Extensions.DependencyInjection/AttributeDataExtensions.cs b/src/Uno.UI.RemoteControl.Host/Extensibility/Uno.Utils.DependencyInjection/AttributeDataExtensions.cs similarity index 65% rename from src/Uno.UI.RemoteControl.Host/Extensibility/Uno.Extensions.DependencyInjection/AttributeDataExtensions.cs rename to src/Uno.UI.RemoteControl.Host/Extensibility/Uno.Utils.DependencyInjection/AttributeDataExtensions.cs index ccf139ef3fa2..b6c737f40eca 100644 --- a/src/Uno.UI.RemoteControl.Host/Extensibility/Uno.Extensions.DependencyInjection/AttributeDataExtensions.cs +++ b/src/Uno.UI.RemoteControl.Host/Extensibility/Uno.Utils.DependencyInjection/AttributeDataExtensions.cs @@ -2,13 +2,26 @@ using System.Linq; using System.Reflection; -namespace Uno.Extensions.DependencyInjection; +namespace Uno.Utils.DependencyInjection; internal static class AttributeDataExtensions { + /// + /// Attempts to create an instance of the specified type from the provided . + /// + /// This offers the ability to a project to implements their own compatible version of the given type to reduce dependencies. + /// Data of an attribute. + /// An instance of if the provided was compatible, `null` otherwise. public static TAttribute? TryCreate(this CustomAttributeData data) => (TAttribute?)TryCreate(data, typeof(TAttribute)); + /// + /// Attempts to create an instance of the specified type from the provided . + /// + /// This offers the ability to a project to implements their own compatible version of the given type to reduce dependencies. + /// Data of an attribute. + /// Type of the attribute to try to instantiate. + /// An instance of if the provided was compatible, `null` otherwise. public static object? TryCreate(this CustomAttributeData data, Type attribute) { if ((!data.AttributeType.FullName?.Equals(attribute.FullName, StringComparison.Ordinal)) ?? true) diff --git a/src/Uno.UI.RemoteControl.Host/Extensibility/Uno.Extensions.DependencyInjection/ServiceAttribute.cs b/src/Uno.UI.RemoteControl.Host/Extensibility/Uno.Utils.DependencyInjection/ServiceAttribute.cs similarity index 97% rename from src/Uno.UI.RemoteControl.Host/Extensibility/Uno.Extensions.DependencyInjection/ServiceAttribute.cs rename to src/Uno.UI.RemoteControl.Host/Extensibility/Uno.Utils.DependencyInjection/ServiceAttribute.cs index bddb48a9b226..7c99d5d2f9c8 100644 --- a/src/Uno.UI.RemoteControl.Host/Extensibility/Uno.Extensions.DependencyInjection/ServiceAttribute.cs +++ b/src/Uno.UI.RemoteControl.Host/Extensibility/Uno.Utils.DependencyInjection/ServiceAttribute.cs @@ -2,7 +2,7 @@ using System.Linq; using Microsoft.Extensions.DependencyInjection; -namespace Uno.Extensions.DependencyInjection; +namespace Uno.Utils.DependencyInjection; /// /// Attribute to define a service registration in the service collection. diff --git a/src/Uno.UI.RemoteControl.Host/Extensibility/Uno.Extensions.DependencyInjection/ServiceCollectionServiceExtensions.cs b/src/Uno.UI.RemoteControl.Host/Extensibility/Uno.Utils.DependencyInjection/ServiceCollectionServiceExtensions.cs similarity index 97% rename from src/Uno.UI.RemoteControl.Host/Extensibility/Uno.Extensions.DependencyInjection/ServiceCollectionServiceExtensions.cs rename to src/Uno.UI.RemoteControl.Host/Extensibility/Uno.Utils.DependencyInjection/ServiceCollectionServiceExtensions.cs index 56b9b5bc04fa..f0b44f9b539e 100644 --- a/src/Uno.UI.RemoteControl.Host/Extensibility/Uno.Extensions.DependencyInjection/ServiceCollectionServiceExtensions.cs +++ b/src/Uno.UI.RemoteControl.Host/Extensibility/Uno.Utils.DependencyInjection/ServiceCollectionServiceExtensions.cs @@ -6,8 +6,9 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; +using Uno.Extensions; -namespace Uno.Extensions.DependencyInjection; +namespace Uno.Utils.DependencyInjection; public static class ServiceCollectionServiceExtensions {