2022-01-02 19:43:55 +11:00
|
|
|
|
using System;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using UniverseLib;
|
2022-01-31 21:24:01 +11:00
|
|
|
|
using UniverseLib.Utility;
|
2022-01-02 19:43:55 +11:00
|
|
|
|
|
|
|
|
|
namespace UnityExplorer.UI.Widgets
|
|
|
|
|
{
|
|
|
|
|
public class GenericArgumentHandler : BaseArgumentHandler
|
|
|
|
|
{
|
|
|
|
|
private Type genericType;
|
|
|
|
|
|
2022-04-22 09:08:17 +10:00
|
|
|
|
public void OnBorrowed(Type genericConstraint)
|
2022-01-02 19:43:55 +11:00
|
|
|
|
{
|
|
|
|
|
this.genericType = genericConstraint;
|
|
|
|
|
|
|
|
|
|
typeCompleter.Enabled = true;
|
|
|
|
|
typeCompleter.BaseType = genericType;
|
|
|
|
|
typeCompleter.CacheTypes();
|
|
|
|
|
|
2022-04-12 05:20:35 +10:00
|
|
|
|
Type[] constraints = genericType.GetGenericParameterConstraints();
|
2022-01-02 19:43:55 +11:00
|
|
|
|
typeCompleter.GenericConstraints = constraints;
|
|
|
|
|
|
2022-04-12 05:20:35 +10:00
|
|
|
|
StringBuilder sb = new($"<color={SignatureHighlighter.CONST}>{genericType.Name}</color>");
|
2022-01-02 19:43:55 +11:00
|
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|