22
33using System ;
44using System . Collections . Generic ;
5+ using System . Threading ;
56using dnlib . DotNet . Emit ;
67
78namespace dnlib . DotNet . Pdb {
@@ -1115,7 +1116,7 @@ public sealed class PdbCompilationOptionsCustomDebugInfo : PdbCustomDebugInfo {
11151116 /// <summary>
11161117 /// Links a TypeDef with no method IL with a PDB document.
11171118 /// </summary>
1118- public sealed class PdbTypeDefinitionDocumentsDebugInfo : PdbCustomDebugInfo {
1119+ public class PdbTypeDefinitionDocumentsDebugInfo : PdbCustomDebugInfo {
11191120 /// <summary>
11201121 /// Returns <see cref="PdbCustomDebugInfoKind.TypeDefinitionDocuments"/>
11211122 /// </summary>
@@ -1127,16 +1128,39 @@ public sealed class PdbTypeDefinitionDocumentsDebugInfo : PdbCustomDebugInfo {
11271128 public override Guid Guid => CustomDebugInfoGuids . TypeDefinitionDocuments ;
11281129
11291130 /// <summary>
1130- /// Document tokens. Only resolvable in debug metadata.
1131- /// A token like this can be resolved by subtracting 1 from the RID and using it as an index into the
1132- /// PdbState.Documents enumerable.
1131+ /// List of documents associated with the type
11331132 /// </summary>
1134- public List < MDToken > DocumentTokens { get ; }
1133+ public IList < PdbDocument > Documents {
1134+ get {
1135+ if ( documents is null )
1136+ InitializeDocuments ( ) ;
1137+ return documents ;
1138+ }
1139+ }
1140+ /// <summary/>
1141+ protected IList < PdbDocument > documents ;
1142+ /// <summary>Initializes <see cref="documents"/></summary>
1143+ protected virtual void InitializeDocuments ( ) =>
1144+ Interlocked . CompareExchange ( ref documents , new List < PdbDocument > ( ) , null ) ;
1145+ }
11351146
1136- /// <summary>
1137- /// Constructor
1138- /// </summary>
1139- public PdbTypeDefinitionDocumentsDebugInfo ( ) => DocumentTokens = new List < MDToken > ( ) ;
1147+ class PdbTypeDefinitionDocumentsDebugInfoMD : PdbTypeDefinitionDocumentsDebugInfo {
1148+ readonly ModuleDef readerModule ;
1149+ readonly IList < MDToken > documentTokens ;
1150+
1151+ protected override void InitializeDocuments ( ) {
1152+ var list = new List < PdbDocument > ( documentTokens . Count ) ;
1153+ for ( var i = 0 ; i < documentTokens . Count ; i ++ ) {
1154+ if ( readerModule . PdbState . tokenToDocument . TryGetValue ( documentTokens [ i ] , out var document ) )
1155+ list . Add ( document ) ;
1156+ }
1157+ Interlocked . CompareExchange ( ref documents , list , null ) ;
1158+ }
1159+
1160+ public PdbTypeDefinitionDocumentsDebugInfoMD ( ModuleDef readerModule , IList < MDToken > documentTokens ) {
1161+ this . readerModule = readerModule ;
1162+ this . documentTokens = documentTokens ;
1163+ }
11401164 }
11411165
11421166 /// <summary>
0 commit comments