hybridclr_unity/Editor/ABI/MethodDesc.cs

78 lines
1.9 KiB
C#
Raw Permalink Normal View History

2022-09-22 08:56:07 +08:00
using dnlib.DotNet;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
2022-10-17 12:16:18 +08:00
namespace HybridCLR.Editor.ABI
2022-09-22 08:56:07 +08:00
{
2022-10-17 12:16:18 +08:00
public class MethodDesc : IEquatable<MethodDesc>
2022-09-22 08:56:07 +08:00
{
public string Sig { get; private set; }
2022-09-22 08:56:07 +08:00
public MethodDef MethodDef { get; set; }
public ReturnInfo ReturnInfo { get; set; }
public List<ParamInfo> ParamInfos { get; set; }
public void Init()
{
for(int i = 0; i < ParamInfos.Count; i++)
{
ParamInfos[i].Index = i;
}
Sig = CreateCallSigName();
2022-09-22 08:56:07 +08:00
}
public void TransfromSigTypes(Func<TypeInfo, bool, TypeInfo> transformer)
{
ReturnInfo.Type = transformer(ReturnInfo.Type, true);
foreach(var paramType in ParamInfos)
{
paramType.Type = transformer(paramType.Type, false);
}
}
public string CreateCallSigName()
{
var n = new StringBuilder();
n.Append(ReturnInfo.Type.CreateSigName());
foreach(var param in ParamInfos)
{
n.Append(param.Type.CreateSigName());
}
return n.ToString();
}
public string CreateInvokeSigName()
{
var n = new StringBuilder();
n.Append(ReturnInfo.Type.CreateSigName());
foreach (var param in ParamInfos)
{
n.Append(param.Type.CreateSigName());
}
return n.ToString();
}
public override bool Equals(object obj)
{
2022-10-17 12:16:18 +08:00
return Equals((MethodDesc)obj);
2022-09-22 08:56:07 +08:00
}
2022-10-17 12:16:18 +08:00
public bool Equals(MethodDesc other)
2022-09-22 08:56:07 +08:00
{
return Sig == other.Sig;
2022-09-22 08:56:07 +08:00
}
public override int GetHashCode()
{
return Sig.GetHashCode();
2022-09-22 08:56:07 +08:00
}
}
}