mirror of
https://github.com/Tyrrrz/CliFx.git
synced 2025-10-25 15:19:17 +00:00
35 lines
1.1 KiB
C#
35 lines
1.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Reflection;
|
|
using CliFx.Utils.Extensions;
|
|
|
|
namespace CliFx.Schema
|
|
{
|
|
internal class BindablePropertyDescriptor : IPropertyDescriptor
|
|
{
|
|
private readonly PropertyInfo _property;
|
|
|
|
public Type Type => _property.PropertyType;
|
|
|
|
public BindablePropertyDescriptor(PropertyInfo property) => _property = property;
|
|
|
|
public object? GetValue(ICommand commandInstance) =>
|
|
_property.GetValue(commandInstance);
|
|
|
|
public void SetValue(ICommand commandInstance, object? value) =>
|
|
_property.SetValue(commandInstance, value);
|
|
|
|
public IReadOnlyList<object?> GetValidValues()
|
|
{
|
|
var underlyingType = Type.TryGetEnumerableUnderlyingType() ?? Type;
|
|
underlyingType = underlyingType.TryGetNullableUnderlyingType() ?? underlyingType;
|
|
|
|
// We can only get valid values for enums
|
|
if (underlyingType.IsEnum)
|
|
return Enum.GetNames(underlyingType);
|
|
|
|
return Array.Empty<object?>();
|
|
}
|
|
}
|
|
}
|