36 internal struct Record : IRecord
39 internal short Semantics;
41 internal int Association;
43 readonly
int IRecord.FilterKey => Association;
45 public readonly
int CompareTo(Record other) => Comparer<int>.Default.Compare(EncodeHasSemantics(Association), EncodeHasSemantics(other.Association));
49 internal const int Index = 0x18;
52 internal const short Setter = 0x0001;
53 internal const short Getter = 0x0002;
54 internal const short Other = 0x0004;
55 internal const short AddOn = 0x0008;
56 internal const short RemoveOn = 0x0010;
57 internal const short Fire = 0x0020;
59 internal override void Read(Reader.MetadataReader mr)
61 for (
int i = 0; i < records.Length; i++)
63 records[i].Semantics = mr.ReadInt16();
64 records[i].Method = mr.ReadMethodDef();
65 records[i].Association = mr.ReadHasSemantics();
69 internal override void Write(ModuleBuilder module)
71 for (
int i = 0; i < rowCount; i++)
72 module.Metadata.AddMethodSemantics(
73 MetadataTokens.EntityHandle(records[i].Association),
74 (
System.Reflection.MethodSemanticsAttributes)records[i].Semantics,
75 MetadataTokens.MethodDefinitionHandle(records[i].Method));
78 static internal int EncodeHasSemantics(
int token) => (token >> 24)
switch
80 EventTable.Index => (token & 0xFFFFFF) << 1 | 0,
82 _ =>
throw new InvalidOperationException(),
85 internal void Fixup(ModuleBuilder moduleBuilder)
87 for (
int i = 0; i < rowCount; i++)
88 moduleBuilder.FixupPseudoToken(
ref records[i].Method);
93 internal MethodInfo GetMethod(Module module,
int token,
bool nonPublic,
short semantics)
95 foreach (
int i
in Filter(token))
97 if ((records[i].Semantics & semantics) != 0)
99 var method = module.ResolveMethod((
MethodDefTable.Index << 24) + records[i].Method);
100 if (nonPublic || method.IsPublic)
101 return (MethodInfo)method;
108 internal MethodInfo[] GetMethods(Module module,
int token,
bool nonPublic,
short semantics)
110 var methods =
new List<MethodInfo>();
111 foreach (
int i
in Filter(token))
113 if ((records[i].Semantics & semantics) != 0)
116 if (nonPublic || method.IsPublic)
121 return methods.ToArray();
124 internal void ComputeFlags(Module module,
int token, out
bool isPublic, out
bool isNonPrivate, out
bool isStatic)
127 isNonPrivate =
false;
130 foreach (
int i
in Filter(token))
132 var method = module.ResolveMethod((
MethodDefTable.Index << 24) + records[i].Method);
133 isPublic |= method.IsPublic;
134 isNonPrivate |= (method.Attributes & MethodAttributes.MemberAccessMask) > MethodAttributes.Private;
135 isStatic |= method.IsStatic;