Skip to content

Commit

Permalink
fix: ignore generic types in type creation dropdown
Browse files Browse the repository at this point in the history
  • Loading branch information
sinnwrig committed Oct 3, 2024
1 parent f5f62bb commit 26c06ad
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
4 changes: 3 additions & 1 deletion Prowl.Editor/Editor/PropertyDrawer/PropertyDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ private static void InterfaceDrawer(Gui gui, string label, int index, Type prope
if (gui.IsNodePressed())
{
gui.OpenPopup("Create_Interface");
implementationTypes = RuntimeUtils.FindTypesImplementing(propertyType);

// Ignore generics since we can't instantiate them
implementationTypes = RuntimeUtils.FindTypesImplementing(propertyType, true);
}
else if (gui.IsNodeHovered())
gui.Draw2D.DrawRectFilled(gui.CurrentNode.LayoutData.Rect, EditorStylePrefs.Instance.Hovering, (float)EditorStylePrefs.Instance.ButtonRoundness);
Expand Down
19 changes: 11 additions & 8 deletions Prowl.Runtime/Utils/RuntimeUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,22 +112,25 @@ public static IEnumerable<Type> GetTypesWithAttribute<T>()
{
var assemblies = AppDomain.CurrentDomain.GetAssemblies();
foreach (var assembly in assemblies)
foreach (var type in assembly.GetTypes())
if (type.GetCustomAttributes(typeof(T), true).Length > 0)
yield return type;
foreach (var type in assembly.GetTypes())
if (type.GetCustomAttributes(typeof(T), true).Length > 0)
yield return type;
}

public static List<Type> FindTypesImplementing(Type propertyType)
public static List<Type> FindTypesImplementing(Type propertyType, bool ignoreGenerics = false)
{
List<Type> types = [];
foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
{
foreach (Type type in asm.GetTypes())
{
if (propertyType.IsAssignableFrom(type) && !type.IsAbstract && !type.IsInterface)
{
types.Add(type);
}
if (!propertyType.IsAssignableFrom(type) || type.IsAbstract || type.IsInterface)
continue;

if (ignoreGenerics && type.IsGenericType)
continue;

types.Add(type);
}
}
return types;
Expand Down

0 comments on commit 26c06ad

Please sign in to comment.