MethodDesc.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using dnlib.DotNet;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Reflection;
  6. using System.Text;
  7. using System.Text.RegularExpressions;
  8. using System.Threading.Tasks;
  9. namespace HybridCLR.Editor.ABI
  10. {
  11. public class MethodDesc : IEquatable<MethodDesc>
  12. {
  13. public string Sig { get; private set; }
  14. public MethodDef MethodDef { get; set; }
  15. public ReturnInfo ReturnInfo { get; set; }
  16. public List<ParamInfo> ParamInfos { get; set; }
  17. public void Init()
  18. {
  19. for(int i = 0; i < ParamInfos.Count; i++)
  20. {
  21. ParamInfos[i].Index = i;
  22. }
  23. Sig = CreateCallSigName();
  24. }
  25. public void TransfromSigTypes(Func<TypeInfo, bool, TypeInfo> transformer)
  26. {
  27. ReturnInfo.Type = transformer(ReturnInfo.Type, true);
  28. foreach(var paramType in ParamInfos)
  29. {
  30. paramType.Type = transformer(paramType.Type, false);
  31. }
  32. }
  33. public string CreateCallSigName()
  34. {
  35. var n = new StringBuilder();
  36. n.Append(ReturnInfo.Type.CreateSigName());
  37. foreach(var param in ParamInfos)
  38. {
  39. n.Append(param.Type.CreateSigName());
  40. }
  41. return n.ToString();
  42. }
  43. public string CreateInvokeSigName()
  44. {
  45. var n = new StringBuilder();
  46. n.Append(ReturnInfo.Type.CreateSigName());
  47. foreach (var param in ParamInfos)
  48. {
  49. n.Append(param.Type.CreateSigName());
  50. }
  51. return n.ToString();
  52. }
  53. public override bool Equals(object obj)
  54. {
  55. return Equals((MethodDesc)obj);
  56. }
  57. public bool Equals(MethodDesc other)
  58. {
  59. return Sig == other.Sig;
  60. }
  61. public override int GetHashCode()
  62. {
  63. return Sig.GetHashCode();
  64. }
  65. }
  66. }