Skip to content

Commit

Permalink
Support nullable immutable array fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
isadorasophia committed May 9, 2024
1 parent f8be74a commit b73e8ca
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Murder.Editor/CustomFields/CustomField.cs
Expand Up @@ -6,8 +6,10 @@
using Murder.Editor.Reflection;
using Murder.Editor.Utilities;
using Murder.Utilities;
using System.Collections.Immutable;
using System.Diagnostics.CodeAnalysis;
using System.Numerics;
using System.Reflection;

namespace Murder.Editor.CustomFields;

Expand Down Expand Up @@ -178,6 +180,13 @@ public static (bool Modified, object? Result) DrawValue(EditorMember member, /*
{
ImGui.OpenPopup($"create_{targetType.Name}");
}
else if (targetType.IsGenericType && targetType.GetGenericTypeDefinition() == typeof(ImmutableArray<>))
{
MethodInfo? create = typeof(ImmutableArray).GetMethod("Create", BindingFlags.Public | BindingFlags.Static, [])?
.MakeGenericMethod(targetType.GenericTypeArguments[0]);

return (true, create?.Invoke(null, null));
}
else
{
return (true, Activator.CreateInstance(targetType));
Expand Down

0 comments on commit b73e8ca

Please sign in to comment.