Skip to content
This repository was archived by the owner on May 9, 2023. It is now read-only.

Commit 942e9d7

Browse files
committed
some commenting
1 parent 9efb958 commit 942e9d7

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

src/Inspectors/Reflection/InteractiveValue/InteractiveValue.cs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,47 @@ namespace UnityExplorer.Inspectors.Reflection
1212
{
1313
public class InteractiveValue
1414
{
15+
/// <summary>
16+
/// Get the <see cref="InteractiveValue"/> subclass which supports the provided <paramref name="type"/>.
17+
/// </summary>
18+
/// <param name="type">The <see cref="Type"/> which you want the <see cref="InteractiveValue"/> Type for.</param>
19+
/// <returns>The best subclass of <see cref="InteractiveValue"/> which supports the provided <paramref name="type"/>.</returns>
1520
public static Type GetIValueForType(Type type)
1621
{
22+
// rather ugly but I couldn't think of a cleaner way that was worth it.
23+
// switch-case doesn't really work here.
24+
25+
// arbitrarily check some types, fastest methods first.
1726
if (type == typeof(bool))
1827
return typeof(InteractiveBool);
19-
else if (type == typeof(string))
20-
return typeof(InteractiveString);
28+
// if type is primitive then it must be a number if its not a bool
2129
else if (type.IsPrimitive)
2230
return typeof(InteractiveNumber);
31+
// check for strings
32+
else if (type == typeof(string))
33+
return typeof(InteractiveString);
34+
// check for enum/flags
2335
else if (typeof(Enum).IsAssignableFrom(type))
2436
{
25-
if (type.GetCustomAttributes(typeof(FlagsAttribute), true) is object[] attributes && attributes.Length > 0)
37+
// NET 3.5 doesn't have "GetCustomAttribute", gotta use the multiple version.
38+
if (type.GetCustomAttributes(typeof(FlagsAttribute), true) is object[] fa && fa.Length > 0)
2639
return typeof(InteractiveFlags);
2740
else
2841
return typeof(InteractiveEnum);
2942
}
43+
// check for unity struct types
3044
else if (InteractiveUnityStruct.SupportsType(type))
3145
return typeof(InteractiveUnityStruct);
46+
// check Transform, force InteractiveValue so they dont become InteractiveEnumerables.
3247
else if (typeof(Transform).IsAssignableFrom(type))
3348
return typeof(InteractiveValue);
49+
// check Dictionaries before Enumerables
3450
else if (ReflectionHelpers.IsDictionary(type))
3551
return typeof(InteractiveDictionary);
52+
// finally check for Enumerables
3653
else if (ReflectionHelpers.IsEnumerable(type))
3754
return typeof(InteractiveEnumerable);
55+
// fallback to default
3856
else
3957
return typeof(InteractiveValue);
4058
}

0 commit comments

Comments
 (0)