diff --git a/CliFx/Schema/IInputSchema.cs b/CliFx/Schema/IInputSchema.cs index 790c690..8ca594c 100644 --- a/CliFx/Schema/IInputSchema.cs +++ b/CliFx/Schema/IInputSchema.cs @@ -9,20 +9,9 @@ namespace CliFx.Schema; public interface IInputSchema { /// - /// Information about the property that this input is bound to. + /// Describes the binding of this input to a CLR property. /// - PropertyDescriptor Property { get; } - - /// - /// Whether this input is a scalar (single value) or a sequence (multiple values). - /// - bool IsScalar { get; } - - /// - /// Valid values for this input, if applicable. - /// If the input does not have a predefined set of valid values, this property is null. - /// - IReadOnlyList? ValidValues { get; } + PropertyBinding Property { get; } /// /// Optional binding converter for this input. diff --git a/CliFx/Schema/OptionSchema.cs b/CliFx/Schema/OptionSchema.cs index 63cf1ff..7e93bdd 100644 --- a/CliFx/Schema/OptionSchema.cs +++ b/CliFx/Schema/OptionSchema.cs @@ -9,7 +9,7 @@ namespace CliFx.Schema; /// Describes a command's option. /// public class OptionSchema( - PropertyDescriptor property, + PropertyBinding property, bool isScalar, IReadOnlyList? validValues, string? name, @@ -22,7 +22,7 @@ public class OptionSchema( ) : IInputSchema { /// - public PropertyDescriptor Property { get; } = property; + public PropertyBinding Property { get; } = property; /// public bool IsScalar { get; } = isScalar; diff --git a/CliFx/Schema/ParameterSchema.cs b/CliFx/Schema/ParameterSchema.cs index 2eb0819..b986de4 100644 --- a/CliFx/Schema/ParameterSchema.cs +++ b/CliFx/Schema/ParameterSchema.cs @@ -7,7 +7,7 @@ namespace CliFx.Schema; /// Describes a command's parameter. /// public class ParameterSchema( - PropertyDescriptor property, + PropertyBinding property, bool isScalar, IReadOnlyList? validValues, int order, @@ -19,7 +19,7 @@ public class ParameterSchema( ) : IInputSchema { /// - public PropertyDescriptor Property { get; } = property; + public PropertyBinding Property { get; } = property; /// public bool IsScalar { get; } = isScalar; diff --git a/CliFx/Schema/PropertyDescriptor.cs b/CliFx/Schema/PropertyBinding.cs similarity index 54% rename from CliFx/Schema/PropertyDescriptor.cs rename to CliFx/Schema/PropertyBinding.cs index 0fed85c..61d4f0c 100644 --- a/CliFx/Schema/PropertyDescriptor.cs +++ b/CliFx/Schema/PropertyBinding.cs @@ -1,24 +1,23 @@ using System; -using System.Diagnostics.CodeAnalysis; +using System.Collections.Generic; +using System.Linq; namespace CliFx.Schema; /// /// Describes a CLR property. /// -public class PropertyDescriptor( - [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)] - Type type, +public class PropertyBinding( + Type propertyType, Func getValue, Action setValue -) + ) { /// - /// Property's CLR type. + /// Underlying property type. /// - [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)] - public Type Type { get; } = type; - + public Type PropertyType { get; } = propertyType; + /// /// Gets the current value of the property on the specified instance. /// @@ -29,3 +28,11 @@ public class PropertyDescriptor( /// public void SetValue(object instance, object? value) => setValue(instance, value); } + +internal static class PropertyBindingExtensions +{ + public static IReadOnlyList? TryGetValidValues(this PropertyBinding binding) => + binding.PropertyType.IsEnum + ? binding.PropertyType.GetEnumValuesAsUnderlyingType().Cast().ToArray() + : null; +} \ No newline at end of file