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

Commit 710b4ba

Browse files
committed
Use switch expression instead of if/else block
1 parent 4bee55f commit 710b4ba

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/UI/Widgets/UnityObjects/UnityObjectWidget.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,16 @@ public static UnityObjectWidget GetUnityWidget(object target, Type targetType, R
2828
if (!typeof(UnityEngine.Object).IsAssignableFrom(targetType))
2929
return null;
3030

31-
UnityObjectWidget ret;
31+
UnityObjectWidget widget = target switch
32+
{
33+
Texture2D => Pool<Texture2DWidget>.Borrow(),
34+
AudioClip => Pool<AudioClipWidget>.Borrow(),
35+
_ => Pool<UnityObjectWidget>.Borrow()
36+
};
3237

33-
if (targetType == typeof(Texture2D))
34-
ret = Pool<Texture2DWidget>.Borrow();
35-
else if (targetType == typeof(AudioClip))
36-
ret = Pool<AudioClipWidget>.Borrow();
37-
else
38-
ret = Pool<UnityObjectWidget>.Borrow();
38+
widget.OnBorrowed(target, targetType, inspector);
3939

40-
ret.OnBorrowed(target, targetType, inspector);
41-
return ret;
40+
return widget;
4241
}
4342

4443
public virtual void OnBorrowed(object target, Type targetType, ReflectionInspector inspector)

0 commit comments

Comments
 (0)