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
|
public interface IInputSchema
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Information about the property that this input is bound to.
|
/// Describes the binding of this input to a CLR property.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
PropertyDescriptor Property { get; }
|
PropertyBinding 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; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Optional binding converter for this input.
|
/// Optional binding converter for this input.
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ namespace CliFx.Schema;
|
|||||||
/// Describes a command's option.
|
/// Describes a command's option.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class OptionSchema(
|
public class OptionSchema(
|
||||||
PropertyDescriptor property,
|
PropertyBinding property,
|
||||||
bool isScalar,
|
bool isScalar,
|
||||||
IReadOnlyList<object?>? validValues,
|
IReadOnlyList<object?>? validValues,
|
||||||
string? name,
|
string? name,
|
||||||
@@ -22,7 +22,7 @@ public class OptionSchema(
|
|||||||
) : IInputSchema
|
) : IInputSchema
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public PropertyDescriptor Property { get; } = property;
|
public PropertyBinding Property { get; } = property;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public bool IsScalar { get; } = isScalar;
|
public bool IsScalar { get; } = isScalar;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ namespace CliFx.Schema;
|
|||||||
/// Describes a command's parameter.
|
/// Describes a command's parameter.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class ParameterSchema(
|
public class ParameterSchema(
|
||||||
PropertyDescriptor property,
|
PropertyBinding property,
|
||||||
bool isScalar,
|
bool isScalar,
|
||||||
IReadOnlyList<object?>? validValues,
|
IReadOnlyList<object?>? validValues,
|
||||||
int order,
|
int order,
|
||||||
@@ -19,7 +19,7 @@ public class ParameterSchema(
|
|||||||
) : IInputSchema
|
) : IInputSchema
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public PropertyDescriptor Property { get; } = property;
|
public PropertyBinding Property { get; } = property;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public bool IsScalar { get; } = isScalar;
|
public bool IsScalar { get; } = isScalar;
|
||||||
|
|||||||
@@ -1,24 +1,23 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace CliFx.Schema;
|
namespace CliFx.Schema;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Describes a CLR property.
|
/// Describes a CLR property.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class PropertyDescriptor(
|
public class PropertyBinding(
|
||||||
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)]
|
Type propertyType,
|
||||||
Type type,
|
|
||||||
Func<object, object?> getValue,
|
Func<object, object?> getValue,
|
||||||
Action<object, object?> setValue
|
Action<object, object?> setValue
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Property's CLR type.
|
/// Underlying property type.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)]
|
public Type PropertyType { get; } = propertyType;
|
||||||
public Type Type { get; } = type;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the current value of the property on the specified instance.
|
/// Gets the current value of the property on the specified instance.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -29,3 +28,11 @@ public class PropertyDescriptor(
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void SetValue(object instance, object? value) => setValue(instance, value);
|
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