Skip to content

Commit d266179

Browse files
committed
Responding to code review feedback.
1 parent bee7863 commit d266179

File tree

6 files changed

+54
-30
lines changed

6 files changed

+54
-30
lines changed

Assets/MixedRealityToolkit.SDK/Features/UX/Interactable/Scripts/Events/InteractableEvent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public ReceiverData AddReceiver(Type type)
9999
/// <returns></returns>
100100
public static InteractableTypesContainer GetEventTypes()
101101
{
102-
return InteractableTypeFinder.Find(candidateEventTypes, InteractableTypeFinder.TypeRestriction.DerivedOnly);
102+
return InteractableTypeFinder.Find(candidateEventTypes, TypeRestriction.DerivedOnly);
103103
}
104104

105105
/// <summary>

Assets/MixedRealityToolkit.SDK/Features/UX/Interactable/Scripts/Profile/InteractableProfileItem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class InteractableProfileItem
4141
/// <returns></returns>
4242
public static InteractableTypesContainer GetThemeTypes()
4343
{
44-
return InteractableTypeFinder.Find(candidateThemeTypes, InteractableTypeFinder.TypeRestriction.DerivedOnly);
44+
return InteractableTypeFinder.Find(candidateThemeTypes, TypeRestriction.DerivedOnly);
4545
}
4646

4747
/// <summary>

Assets/MixedRealityToolkit.SDK/Features/UX/Interactable/Scripts/States/States.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public InteractableStates SetupLogic()
5959

6060
public void SetupStateOptions()
6161
{
62-
StateOptions = InteractableTypeFinder.Find(candidateStateTypes, InteractableTypeFinder.TypeRestriction.AllowBase);
62+
StateOptions = InteractableTypeFinder.Find(candidateStateTypes, TypeRestriction.AllowBase);
6363
}
6464

6565
// redundant method, put in a utils with static methods!!!

Assets/MixedRealityToolkit.SDK/Features/UX/Interactable/Scripts/TypeResolution/InteractableTypeFinder.cs

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,6 @@ namespace Microsoft.MixedReality.Toolkit.SDK.UX.Interactable.TypeResolution
1010
/// </summary>
1111
public class InteractableTypeFinder
1212
{
13-
/// <summary>
14-
/// Controls the behavior of the InteractableTypeFinder.FindTypes function. See individual
15-
/// enum values for more details.
16-
/// </summary>
17-
public enum TypeRestriction
18-
{
19-
/// <summary>
20-
/// When this is specified, only classes derived from the specified type will be
21-
/// returned by the lookup. This means that if you pass InteractableStates, the
22-
/// lookup will only return classes whose base class is InteractableStates but
23-
/// will not return InteractableStates itself.
24-
/// </summary>
25-
DerivedOnly,
26-
27-
/// <summary>
28-
/// When this is specified, classes derived from the specified type AND the class
29-
/// itself will be returned by the lookup. This means that if you pass
30-
/// InteractableStates, the lookup will both classes whose base class is
31-
/// InteractableStates and InteractableStates itself.
32-
/// </summary>
33-
AllowBase,
34-
};
35-
3613
/// <summary>
3714
/// A convenience wrapper provided for editor code to turn a list of types into a form that
3815
/// matches their existing structure.
@@ -119,14 +96,19 @@ private static void EnsureCacheForTypes(List<Type> types, TypeRestriction typeRe
11996
private static List<InteractableType> GetTypesFromAssemblies(Type type, TypeRestriction typeRestriction, Assembly[] assemblies)
12097
{
12198
List<InteractableType> interactableTypes = new List<InteractableType>();
99+
100+
if (typeRestriction == TypeRestriction.AllowBase)
101+
{
102+
InteractableType interactableType = new InteractableType(type);
103+
interactableTypes.Add(interactableType);
104+
}
105+
122106
foreach (Assembly assembly in assemblies)
123107
{
124108
foreach (Type assemblyType in assembly.GetTypes())
125109
{
126-
TypeInfo info = assemblyType.GetTypeInfo();
127-
bool exactBaseMatch = typeRestriction == TypeRestriction.AllowBase && assemblyType.Equals(type);
128-
bool derivedMatch = info.BaseType != null && info.BaseType.Equals(type);
129-
if (exactBaseMatch || derivedMatch)
110+
TypeInfo info = assemblyType.GetTypeInfo();
111+
if (info.IsSubclassOf(type))
130112
{
131113
InteractableType interactableType = new InteractableType(assemblyType);
132114
interactableTypes.Add(interactableType);
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace Microsoft.MixedReality.Toolkit.SDK.UX.Interactable.TypeResolution
8+
{
9+
/// <summary>
10+
/// Controls the behavior of the InteractableTypeFinder.FindTypes function. See individual
11+
/// enum values for more details.
12+
/// </summary>
13+
public enum TypeRestriction
14+
{
15+
/// <summary>
16+
/// When this is specified, only classes derived from the specified type will be
17+
/// returned by the lookup. This means that if you pass InteractableStates, the
18+
/// lookup will only return classes whose base class is InteractableStates but
19+
/// will not return InteractableStates itself.
20+
/// </summary>
21+
DerivedOnly,
22+
23+
/// <summary>
24+
/// When this is specified, classes derived from the specified type AND the class
25+
/// itself will be returned by the lookup. This means that if you pass
26+
/// InteractableStates, the lookup will both classes whose base class is
27+
/// InteractableStates and InteractableStates itself.
28+
/// </summary>
29+
AllowBase,
30+
};
31+
}

Assets/MixedRealityToolkit.SDK/Features/UX/Interactable/Scripts/TypeResolution/TypeRestriction.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)