ConstraintContext.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using dnlib.DotNet;
  2. using HybridCLR.Editor.Meta;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace HybridCLR.Editor.AOT
  9. {
  10. public class ConstraintContext
  11. {
  12. public class ImplType
  13. {
  14. public TypeSig BaseType { get; }
  15. public List<TypeSig> Interfaces { get; }
  16. public bool ValueType { get; }
  17. private readonly int _hash;
  18. public ImplType(TypeSig baseType, List<TypeSig> interfaces, bool valueType)
  19. {
  20. BaseType = baseType;
  21. Interfaces = interfaces;
  22. ValueType = valueType;
  23. _hash = ComputHash();
  24. }
  25. public override bool Equals(object obj)
  26. {
  27. ImplType o = (ImplType)obj;
  28. return MetaUtil.EqualsTypeSig(this.BaseType, o.BaseType)
  29. && MetaUtil.EqualsTypeSigArray(this.Interfaces, o.Interfaces)
  30. && this.ValueType == o.ValueType;
  31. }
  32. public override int GetHashCode()
  33. {
  34. return _hash;
  35. }
  36. private int ComputHash()
  37. {
  38. int hash = 0;
  39. if (BaseType != null)
  40. {
  41. hash = HashUtil.CombineHash(hash, TypeEqualityComparer.Instance.GetHashCode(BaseType));
  42. }
  43. if (Interfaces.Count > 0)
  44. {
  45. hash = HashUtil.CombineHash(hash, HashUtil.ComputHash(Interfaces));
  46. }
  47. return hash;
  48. }
  49. }
  50. public HashSet<ImplType> ImplTypes { get; } = new HashSet<ImplType>();
  51. public GenericClass ApplyConstraints(GenericClass gc)
  52. {
  53. return gc;
  54. }
  55. public GenericMethod ApplyConstraints(GenericMethod gm)
  56. {
  57. return gm;
  58. }
  59. }
  60. }