From 0fc88a42baf1499d416b7d95facce5d1c2b5e5e1 Mon Sep 17 00:00:00 2001 From: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com> Date: Tue, 3 Sep 2024 03:39:15 +0300 Subject: [PATCH] asd --- CliFx/Formatting/HelpConsoleFormatter.cs | 4 ++-- CliFx/Schema/CommandInputSchema.cs | 2 +- CliFx/Schema/CommandOptionSchema.cs | 2 +- CliFx/Schema/CommandParameterSchema.cs | 2 +- CliFx/Schema/PropertyBinding.cs | 6 +++--- CliFx/Utils/Extensions/StringExtensions.cs | 12 +----------- CliFx/Utils/Extensions/TypeExtensions.cs | 15 --------------- 7 files changed, 9 insertions(+), 34 deletions(-) delete mode 100644 CliFx/Utils/Extensions/TypeExtensions.cs diff --git a/CliFx/Formatting/HelpConsoleFormatter.cs b/CliFx/Formatting/HelpConsoleFormatter.cs index c240e36..21a1be2 100644 --- a/CliFx/Formatting/HelpConsoleFormatter.cs +++ b/CliFx/Formatting/HelpConsoleFormatter.cs @@ -306,12 +306,12 @@ internal class HelpConsoleFormatter(ConsoleWriter consoleWriter, HelpContext con if (defaultValue is null) return; - if (schema.Property.Type.IsToStringOverriden()) + if (defaultValue is IFormattable formattable) { Write(ConsoleColor.White, "Default: "); Write('"'); - Write(defaultValue.ToString(CultureInfo.InvariantCulture)); + Write(formattable.ToString(null, CultureInfo.InvariantCulture)); Write('"'); Write('.'); } diff --git a/CliFx/Schema/CommandInputSchema.cs b/CliFx/Schema/CommandInputSchema.cs index 0e59c20..eda2a71 100644 --- a/CliFx/Schema/CommandInputSchema.cs +++ b/CliFx/Schema/CommandInputSchema.cs @@ -126,7 +126,7 @@ public abstract class CommandInputSchema( public abstract class CommandInputSchema< TCommand, [DynamicallyAccessedMembers( - DynamicallyAccessedMemberTypes.Interfaces | DynamicallyAccessedMemberTypes.PublicMethods + DynamicallyAccessedMemberTypes.PublicMethods )] TProperty >( diff --git a/CliFx/Schema/CommandOptionSchema.cs b/CliFx/Schema/CommandOptionSchema.cs index 16f7faa..76c114c 100644 --- a/CliFx/Schema/CommandOptionSchema.cs +++ b/CliFx/Schema/CommandOptionSchema.cs @@ -64,7 +64,7 @@ public class CommandOptionSchema( public class CommandOptionSchema< TCommand, [DynamicallyAccessedMembers( - DynamicallyAccessedMemberTypes.Interfaces | DynamicallyAccessedMemberTypes.PublicMethods + DynamicallyAccessedMemberTypes.PublicMethods )] TProperty >( diff --git a/CliFx/Schema/CommandParameterSchema.cs b/CliFx/Schema/CommandParameterSchema.cs index 5daf9c4..3cd28eb 100644 --- a/CliFx/Schema/CommandParameterSchema.cs +++ b/CliFx/Schema/CommandParameterSchema.cs @@ -43,7 +43,7 @@ public class CommandParameterSchema( public class CommandParameterSchema< TCommand, [DynamicallyAccessedMembers( - DynamicallyAccessedMemberTypes.Interfaces | DynamicallyAccessedMemberTypes.PublicMethods + DynamicallyAccessedMemberTypes.PublicMethods )] TProperty >( diff --git a/CliFx/Schema/PropertyBinding.cs b/CliFx/Schema/PropertyBinding.cs index 36130a8..def6f37 100644 --- a/CliFx/Schema/PropertyBinding.cs +++ b/CliFx/Schema/PropertyBinding.cs @@ -10,7 +10,7 @@ namespace CliFx.Schema; /// public class PropertyBinding( [DynamicallyAccessedMembers( - DynamicallyAccessedMemberTypes.Interfaces | DynamicallyAccessedMemberTypes.PublicMethods + DynamicallyAccessedMemberTypes.PublicMethods )] Type type, Func getValue, @@ -21,7 +21,7 @@ public class PropertyBinding( /// Underlying CLR type of the property. /// [DynamicallyAccessedMembers( - DynamicallyAccessedMemberTypes.Interfaces | DynamicallyAccessedMemberTypes.PublicMethods + DynamicallyAccessedMemberTypes.PublicMethods )] public Type Type { get; } = type; @@ -64,7 +64,7 @@ public class PropertyBinding( public class PropertyBinding< TObject, [DynamicallyAccessedMembers( - DynamicallyAccessedMemberTypes.Interfaces | DynamicallyAccessedMemberTypes.PublicMethods + DynamicallyAccessedMemberTypes.PublicMethods )] TProperty >(Func getValue, Action setValue) diff --git a/CliFx/Utils/Extensions/StringExtensions.cs b/CliFx/Utils/Extensions/StringExtensions.cs index 5032a20..e387d90 100644 --- a/CliFx/Utils/Extensions/StringExtensions.cs +++ b/CliFx/Utils/Extensions/StringExtensions.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; namespace CliFx.Utils.Extensions; @@ -14,13 +13,4 @@ internal static class StringExtensions public static string JoinToString(this IEnumerable source, string separator) => string.Join(separator, source); - - public static string? ToString( - this object obj, - IFormatProvider? formatProvider = null, - string? format = null - ) => - obj is IFormattable formattable - ? formattable.ToString(format, formatProvider) - : obj.ToString(); } diff --git a/CliFx/Utils/Extensions/TypeExtensions.cs b/CliFx/Utils/Extensions/TypeExtensions.cs deleted file mode 100644 index 1040ab5..0000000 --- a/CliFx/Utils/Extensions/TypeExtensions.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Diagnostics.CodeAnalysis; - -namespace CliFx.Utils.Extensions; - -internal static class TypeExtensions -{ - public static bool IsToStringOverriden( - [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] this Type type - ) - { - var toStringMethod = type.GetMethod(nameof(ToString), []); - return toStringMethod?.GetBaseDefinition().DeclaringType != toStringMethod?.DeclaringType; - } -}