Fix crashes due to EnumerableEditorView being used on inappropriate types

This commit is contained in:
Yoshi Askharoun
2023-06-05 16:02:26 -05:00
parent 4315e1e4aa
commit b95b1fd624
2 changed files with 8 additions and 4 deletions
@@ -21,9 +21,10 @@ public class EnumerableEditorViewModel : EditorBase<IEnumerable>, ILabelledInspe
public override bool IsReadOnly => Value is IList collection && collection.IsReadOnly;
public IEnumerable<InspectorViewModel> Inspectables => Value
public IEnumerable<InspectorViewModel> Inspectables => Value?
.Cast<object>()
.Select(inst => new InspectorViewModel() { SelectedObject = Builder(inst) });
.Select(inst => new InspectorViewModel() { SelectedObject = Builder(inst) })
?? Array.Empty<InspectorViewModel>();
private static InspectableObject DefaultBuilder(object instance)
{
@@ -1,4 +1,5 @@
using System.Collections;
using Newtonsoft.Json.Linq;
using System.Collections;
using System.ComponentModel;
namespace ZuneUIXTools.Modules.Inspectors;
@@ -7,6 +8,8 @@ public class EnumerablePropertyEditorBuilder : InheritablePropertyEditorBuilder<
{
public override bool IsApplicable(PropertyDescriptor propertyDescriptor)
{
return base.IsApplicable(propertyDescriptor) && propertyDescriptor.PropertyType != typeof(string);
return base.IsApplicable(propertyDescriptor)
&& propertyDescriptor.PropertyType != typeof(string)
&& !propertyDescriptor.PropertyType.IsAssignableTo(typeof(JToken));
}
}