Skip to content

Commit

Permalink
Split TypeFilters into two parts: one for any .NET and one for Unity
Browse files Browse the repository at this point in the history
  • Loading branch information
Exanite committed Nov 26, 2024
1 parent 550cdec commit 4fb8e0e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 38 deletions.
40 changes: 40 additions & 0 deletions Types/TypeFilters.Unity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#if UNITY_2021_3_OR_NEWER
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using Object = UnityEngine.Object;

namespace Exanite.Core.Types
{
public static partial class TypeFilters
{
/// <summary>
/// Types ignored by the <see cref="UnitySmart"/> <see cref="ITypeFilter"/>.
/// </summary>
public static IReadOnlyCollection<Type> UnityIgnoredTypes { get; }

public static ITypeFilter UnitySmart { get; }

static TypeFilters()
{
UnityIgnoredTypes = new HashSet<Type>
{
typeof(MonoBehaviour),
typeof(Behaviour),
typeof(Component),
typeof(ScriptableObject),
typeof(Object),
typeof(UIBehaviour),
typeof(Graphic),
typeof(MaskableGraphic),
};

UnitySmart = new TypeFilter()
.Add(new InheritanceHierarchyTypeFilter(UnityIgnoredTypes, false, false))
.Interfaces();
}
}
}
#endif
39 changes: 1 addition & 38 deletions Types/TypeFilters.cs
Original file line number Diff line number Diff line change
@@ -1,47 +1,10 @@
using System;
using System.Collections.Generic;
#if UNITY_2021_3_OR_NEWER
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using Object = UnityEngine.Object;
#endif

namespace Exanite.Core.Types
{
public static class TypeFilters
public static partial class TypeFilters
{
public static ITypeFilter Self { get; } = new SelfTypeFilter();
public static ITypeFilter Interface { get; } = new InterfaceTypeFilter();
public static ITypeFilter InheritanceHierarchy { get; } = new InheritanceHierarchyTypeFilter();
public static ITypeFilter Smart { get; } = new TypeFilter().InheritanceHierarchy().Interfaces();

#if UNITY_2021_3_OR_NEWER
/// <summary>
/// Types ignored by the <see cref="UnitySmart"/> <see cref="ITypeFilter"/>.
/// </summary>
public static IReadOnlyCollection<Type> UnityIgnoredTypes { get; }

public static ITypeFilter UnitySmart { get; }

static TypeFilters()
{
UnityIgnoredTypes = new HashSet<Type>
{
typeof(MonoBehaviour),
typeof(Behaviour),
typeof(Component),
typeof(ScriptableObject),
typeof(Object),
typeof(UIBehaviour),
typeof(Graphic),
typeof(MaskableGraphic),
};

UnitySmart = new TypeFilter()
.Add(new InheritanceHierarchyTypeFilter(UnityIgnoredTypes, false, false))
.Interfaces();
}
#endif
}
}

0 comments on commit 4fb8e0e

Please sign in to comment.