mirror of
https://github.com/Tyrrrz/CliFx.git
synced 2025-10-25 15:19:17 +00:00
asd
This commit is contained in:
@@ -9,20 +9,9 @@ namespace CliFx.Schema;
|
||||
public interface IInputSchema
|
||||
{
|
||||
/// <summary>
|
||||
/// Information about the property that this input is bound to.
|
||||
/// Describes the binding of this input to a CLR property.
|
||||
/// </summary>
|
||||
PropertyDescriptor Property { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether this input is a scalar (single value) or a sequence (multiple values).
|
||||
/// </summary>
|
||||
bool IsScalar { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Valid values for this input, if applicable.
|
||||
/// If the input does not have a predefined set of valid values, this property is <c>null</c>.
|
||||
/// </summary>
|
||||
IReadOnlyList<object?>? ValidValues { get; }
|
||||
PropertyBinding Property { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Optional binding converter for this input.
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace CliFx.Schema;
|
||||
/// Describes a command's option.
|
||||
/// </summary>
|
||||
public class OptionSchema(
|
||||
PropertyDescriptor property,
|
||||
PropertyBinding property,
|
||||
bool isScalar,
|
||||
IReadOnlyList<object?>? validValues,
|
||||
string? name,
|
||||
@@ -22,7 +22,7 @@ public class OptionSchema(
|
||||
) : IInputSchema
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public PropertyDescriptor Property { get; } = property;
|
||||
public PropertyBinding Property { get; } = property;
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool IsScalar { get; } = isScalar;
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace CliFx.Schema;
|
||||
/// Describes a command's parameter.
|
||||
/// </summary>
|
||||
public class ParameterSchema(
|
||||
PropertyDescriptor property,
|
||||
PropertyBinding property,
|
||||
bool isScalar,
|
||||
IReadOnlyList<object?>? validValues,
|
||||
int order,
|
||||
@@ -19,7 +19,7 @@ public class ParameterSchema(
|
||||
) : IInputSchema
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public PropertyDescriptor Property { get; } = property;
|
||||
public PropertyBinding Property { get; } = property;
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool IsScalar { get; } = isScalar;
|
||||
|
||||
@@ -1,23 +1,22 @@
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace CliFx.Schema;
|
||||
|
||||
/// <summary>
|
||||
/// Describes a CLR property.
|
||||
/// </summary>
|
||||
public class PropertyDescriptor(
|
||||
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)]
|
||||
Type type,
|
||||
public class PropertyBinding(
|
||||
Type propertyType,
|
||||
Func<object, object?> getValue,
|
||||
Action<object, object?> setValue
|
||||
)
|
||||
{
|
||||
/// <summary>
|
||||
/// Property's CLR type.
|
||||
/// Underlying property type.
|
||||
/// </summary>
|
||||
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)]
|
||||
public Type Type { get; } = type;
|
||||
public Type PropertyType { get; } = propertyType;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current value of the property on the specified instance.
|
||||
@@ -29,3 +28,11 @@ public class PropertyDescriptor(
|
||||
/// </summary>
|
||||
public void SetValue(object instance, object? value) => setValue(instance, value);
|
||||
}
|
||||
|
||||
internal static class PropertyBindingExtensions
|
||||
{
|
||||
public static IReadOnlyList<object?>? TryGetValidValues(this PropertyBinding binding) =>
|
||||
binding.PropertyType.IsEnum
|
||||
? binding.PropertyType.GetEnumValuesAsUnderlyingType().Cast<object?>().ToArray()
|
||||
: null;
|
||||
}
|
||||
Reference in New Issue
Block a user