Skip to content

Commit

Permalink
xmldoc and nrt warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
tznind committed Mar 9, 2025
1 parent 6e89a47 commit 05fb446
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/ArrayExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ public static IListDataSource ToListDataSource(this IEnumerable enumerable)

// Create an instance of ListWrapper<T>
var listWrapperType = typeof(ListWrapper<>).MakeGenericType(elementType);
return (IListDataSource)Activator.CreateInstance(listWrapperType, list);
return (IListDataSource)(Activator.CreateInstance(listWrapperType, list)
?? throw new Exception("CreateInstance inexplicably returned null"));
}

}
1 change: 1 addition & 0 deletions src/ToCode/InstanceOfProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public InstanceOfProperty(Design design, PropertyInfo property)
?? throw new Exception("Unable to determine property type");
}

/// <inheritdoc/>
public override CodeExpression GetRhs()
{
var instance = this.GetValue();
Expand Down
6 changes: 3 additions & 3 deletions src/ToCode/Property.cs
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,9 @@ private CodeExpression ValueFactory(object val)
if (type.GetGenericTypeDefinition() == typeof(SliderOption<>))
{
// TODO: this feels very brittle!
var a1 = type.GetProperty(nameof(SliderOption<object>.Legend)).GetValue(val);
var a2 = (Rune)type.GetProperty(nameof(SliderOption<object>.LegendAbbr)).GetValue(val);
var a3 = type.GetProperty(nameof(SliderOption<object>.Data)).GetValue(val);
var a1 = type.GetPropertyOrThrow(nameof(SliderOption<object>.Legend)).GetValue(val);
var a2 = (Rune)type.GetPropertyOrThrow(nameof(SliderOption<object>.LegendAbbr)).GetValue(val)!;
var a3 = type.GetPropertyOrThrow(nameof(SliderOption<object>.Data)).GetValue(val);


return new CodeObjectCreateExpression(
Expand Down
15 changes: 15 additions & 0 deletions src/TypeExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Collections;
using System.Reflection;
using Terminal.Gui;

namespace TerminalGuiDesigner
{
Expand Down Expand Up @@ -47,5 +49,18 @@ public static bool IsGenericType(this Type type, Type genericParentHypothesis)
{
return type.IsGenericType && type.GetGenericTypeDefinition() == genericParentHypothesis;
}

/// <summary>
/// Returns the <see cref="Type.GetProperty(string)"/> of the given <paramref name="name"/>
/// or throws an <see cref="Exception"/>.
/// </summary>
/// <param name="type"></param>
/// <param name="name"></param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
public static PropertyInfo GetPropertyOrThrow(this Type type, string name)
{
return type.GetProperty(name) ?? throw new Exception($"Could not find expected property {name} on type {type}");
}
}
}
8 changes: 7 additions & 1 deletion src/UI/Windows/ArrayEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ namespace TerminalGuiDesigner.UI.Windows {
using Terminal.Gui;
using TerminalGuiDesigner.ToCode;

/// <summary>
/// UI for configuring array elements
/// </summary>
public partial class ArrayEditor : IValueGetterDialog {

/// <summary>
Expand All @@ -29,8 +32,11 @@ public partial class ArrayEditor : IValueGetterDialog {
/// <summary>
/// The new array
/// </summary>
[CanBeNull]
public object Result => ResultAsList;

/// <summary>
/// Returns the <see cref="Array"/> being designed as an <see cref="IList"/>
/// </summary>
public IList ResultAsList { get; private set; }


Expand Down

0 comments on commit 05fb446

Please sign in to comment.