mirror of
https://github.com/sinai-dev/UnityExplorer.git
synced 2025-06-17 14:37:49 +08:00
59 lines
1.6 KiB
C#
59 lines
1.6 KiB
C#
using System;
|
|
using System.Text;
|
|
using UniverseLib;
|
|
using UniverseLib.Utility;
|
|
|
|
namespace UnityExplorer.UI.Widgets
|
|
{
|
|
public class GenericArgumentHandler : BaseArgumentHandler
|
|
{
|
|
private Type genericType;
|
|
|
|
public void OnBorrowed(Type genericConstraint)
|
|
{
|
|
this.genericType = genericConstraint;
|
|
|
|
typeCompleter.Enabled = true;
|
|
typeCompleter.BaseType = genericType;
|
|
typeCompleter.CacheTypes();
|
|
|
|
Type[] constraints = genericType.GetGenericParameterConstraints();
|
|
typeCompleter.GenericConstraints = constraints;
|
|
|
|
StringBuilder sb = new($"<color={SignatureHighlighter.CONST}>{genericType.Name}</color>");
|
|
|
|
for (int j = 0; j < constraints.Length; j++)
|
|
{
|
|
if (j == 0) sb.Append(' ').Append('(');
|
|
else sb.Append(',').Append(' ');
|
|
|
|
sb.Append(SignatureHighlighter.Parse(constraints[j], false));
|
|
|
|
if (j + 1 == constraints.Length)
|
|
sb.Append(')');
|
|
}
|
|
|
|
argNameLabel.text = sb.ToString();
|
|
}
|
|
|
|
public void OnReturned()
|
|
{
|
|
this.genericType = null;
|
|
|
|
this.typeCompleter.Enabled = false;
|
|
|
|
this.inputField.Text = "";
|
|
}
|
|
|
|
public Type Evaluate()
|
|
{
|
|
return ReflectionUtility.GetTypeByName(this.inputField.Text)
|
|
?? throw new Exception($"Could not find any type by name '{this.inputField.Text}'!");
|
|
}
|
|
|
|
public override void CreateSpecialContent()
|
|
{
|
|
}
|
|
}
|
|
}
|