diff --git a/CliFx.Demo/Domain/LibraryProvider.cs b/CliFx.Demo/Domain/LibraryProvider.cs index 6e9e79b..4fe2137 100644 --- a/CliFx.Demo/Domain/LibraryProvider.cs +++ b/CliFx.Demo/Domain/LibraryProvider.cs @@ -21,7 +21,7 @@ namespace CliFx.Demo.Domain var data = File.ReadAllText(StorageFilePath); - return JsonConvert.DeserializeObject(data); + return JsonConvert.DeserializeObject(data) ?? Library.Empty; } public Book? TryGetBook(string title) => GetLibrary().Books.FirstOrDefault(b => b.Title == title); diff --git a/CliFx.Tests/HelpTextSpecs.cs b/CliFx.Tests/HelpTextSpecs.cs index cf9a646..325eb09 100644 --- a/CliFx.Tests/HelpTextSpecs.cs +++ b/CliFx.Tests/HelpTextSpecs.cs @@ -590,10 +590,10 @@ public enum CustomEnum { One, Two, Three } public class Command : ICommand { [CommandParameter(0)] - public List Foo { get; set; } + public IReadOnlyList Foo { get; set; } [CommandOption(""bar"")] - public List Bar { get; set; } + public IReadOnlyList Bar { get; set; } public ValueTask ExecuteAsync(IConsole console) => default; } @@ -638,7 +638,7 @@ public class Command : ICommand public CustomEnum? Foo { get; set; } [CommandOption(""bar"")] - public List Bar { get; set; } + public IReadOnlyList Bar { get; set; } public ValueTask ExecuteAsync(IConsole console) => default; } diff --git a/CliFx/Schema/BindablePropertyDescriptor.cs b/CliFx/Schema/BindablePropertyDescriptor.cs index 6eacafa..e620ddb 100644 --- a/CliFx/Schema/BindablePropertyDescriptor.cs +++ b/CliFx/Schema/BindablePropertyDescriptor.cs @@ -21,8 +21,20 @@ namespace CliFx.Schema public IReadOnlyList GetValidValues() { - var underlyingType = Type.TryGetEnumerableUnderlyingType() ?? Type; - underlyingType = underlyingType.TryGetNullableUnderlyingType() ?? underlyingType; + static Type GetUnderlyingType(Type type) + { + var enumerableUnderlyingType = type.TryGetEnumerableUnderlyingType(); + if (enumerableUnderlyingType is not null) + return GetUnderlyingType(enumerableUnderlyingType); + + var nullableUnderlyingType = type.TryGetNullableUnderlyingType(); + if (nullableUnderlyingType is not null) + return GetUnderlyingType(nullableUnderlyingType); + + return type; + } + + var underlyingType = GetUnderlyingType(Type); // We can only get valid values for enums if (underlyingType.IsEnum)