55using System . Reflection . Metadata ;
66using System . Reflection ;
77using System . Reflection . Metadata . Ecma335 ;
8+ using System . IO ;
89
910namespace Semmle . Extraction . CIL . Entities
1011{
1112 /// <summary>
1213 /// An entity represting a member.
1314 /// Used to type tuples correctly.
1415 /// </summary>
15- interface IMember : ILabelledEntity
16+ interface IMember : IExtractedEntity
1617 {
1718 }
1819
@@ -36,18 +37,24 @@ protected Field(Context cx) : base(cx)
3637
3738 public Label Label { get ; set ; }
3839
39- public IId Id => ShortId + IdSuffix ;
40-
41- public Id IdSuffix => fieldSuffix ;
42-
43- static readonly StringId fieldSuffix = new StringId ( ";cil-field" ) ;
40+ public void WriteId ( TextWriter trapFile )
41+ {
42+ trapFile . WriteSubId ( DeclaringType ) ;
43+ trapFile . Write ( '.' ) ;
44+ trapFile . Write ( Name ) ;
45+ }
4446
45- public Id ShortId
47+ public void WriteQuotedId ( TextWriter trapFile )
4648 {
47- get ; set ;
49+ trapFile . Write ( "@\" " ) ;
50+ WriteId ( trapFile ) ;
51+ trapFile . Write ( IdSuffix ) ;
52+ trapFile . Write ( '\" ' ) ;
4853 }
4954
50- public abstract Id Name { get ; }
55+ public string IdSuffix => ";cil-field" ;
56+
57+ public abstract string Name { get ; }
5158
5259 public abstract Type DeclaringType { get ; }
5360
@@ -59,7 +66,7 @@ public virtual IEnumerable<IExtractionProduct> Contents
5966 {
6067 get
6168 {
62- yield return Tuples . cil_field ( this , DeclaringType , Name . Value , Type ) ;
69+ yield return Tuples . cil_field ( this , DeclaringType , Name , Type ) ;
6370 }
6471 }
6572
@@ -82,9 +89,15 @@ public DefinitionField(GenericContext gc, FieldDefinitionHandle handle) : base(g
8289 this . handle = handle ;
8390 this . gc = gc ;
8491 fd = cx . mdReader . GetFieldDefinition ( handle ) ;
85- ShortId = DeclaringType . ShortId + cx . Dot + Name ;
8692 }
8793
94+ public override bool Equals ( object obj )
95+ {
96+ return obj is DefinitionField field && handle . Equals ( field . handle ) ;
97+ }
98+
99+ public override int GetHashCode ( ) => handle . GetHashCode ( ) ;
100+
88101 public override IEnumerable < IExtractionProduct > Contents
89102 {
90103 get
@@ -114,7 +127,7 @@ public override IEnumerable<IExtractionProduct> Contents
114127 }
115128 }
116129
117- public override Id Name => cx . GetId ( fd . Name ) ;
130+ public override string Name => cx . GetString ( fd . Name ) ;
118131
119132 public override Type DeclaringType => ( Type ) cx . Create ( fd . GetDeclaringType ( ) ) ;
120133
@@ -127,19 +140,30 @@ public override IEnumerable<IExtractionProduct> Contents
127140
128141 sealed class MemberReferenceField : Field
129142 {
143+ readonly MemberReferenceHandle Handle ;
130144 readonly MemberReference mr ;
131145 readonly GenericContext gc ;
132146 readonly Type declType ;
133147
134148 public MemberReferenceField ( GenericContext gc , MemberReferenceHandle handle ) : base ( gc . cx )
135149 {
150+ Handle = handle ;
136151 this . gc = gc ;
137152 mr = cx . mdReader . GetMemberReference ( handle ) ;
138153 declType = ( Type ) cx . CreateGeneric ( gc , mr . Parent ) ;
139- ShortId = declType . ShortId + cx . Dot + Name ;
140154 }
141155
142- public override Id Name => cx . GetId ( mr . Name ) ;
156+ public override bool Equals ( object obj )
157+ {
158+ return obj is MemberReferenceField field && Handle . Equals ( field . Handle ) ;
159+ }
160+
161+ public override int GetHashCode ( )
162+ {
163+ return Handle . GetHashCode ( ) ;
164+ }
165+
166+ public override string Name => cx . GetString ( mr . Name ) ;
143167
144168 public override Type DeclaringType => declType ;
145169
0 commit comments