Skip to content

Commit

Permalink
Move get logic to Mixin helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
sbomer committed Jun 4, 2024
1 parent c9a02db commit e533f35
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 24 deletions.
5 changes: 3 additions & 2 deletions Mono.Cecil.Cil/PortablePdb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using System.IO;
using System.IO.Compression;
using System.Security.Cryptography;
using Mono.Collections.Generic;
using Mono.Cecil.Metadata;
using Mono.Cecil.PE;

Expand Down Expand Up @@ -145,7 +146,7 @@ void ReadStateMachineKickOffMethod (MethodDebugInformation method_info)
method_info.kickoff_method = debug_reader.ReadStateMachineKickoffMethod (method_info.method);
}

public Collections.Generic.Collection<CustomDebugInformation> Read (ICustomDebugInformationProvider provider)
public Collection<CustomDebugInformation> Read (ICustomDebugInformationProvider provider)
{
return debug_reader.GetCustomDebugInformation (provider);
}
Expand Down Expand Up @@ -226,7 +227,7 @@ public MethodDebugInformation Read (MethodDefinition method)
return reader.Read (method);
}

public Collections.Generic.Collection<CustomDebugInformation> Read (ICustomDebugInformationProvider provider)
public Collection<CustomDebugInformation> Read (ICustomDebugInformationProvider provider)
{
return reader.Read (provider);
}
Expand Down
33 changes: 33 additions & 0 deletions Mono.Cecil.Cil/Symbols.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1226,5 +1226,38 @@ public static bool IsPortablePdb (Stream stream)
stream.Position = position;
}
}

public static bool GetHasCustomDebugInformations (
this ICustomDebugInformationProvider self,
ref Collection<CustomDebugInformation> collection,
ModuleDefinition module)
{
if (module.HasImage ())
module.Read (ref collection, self, (provider, reader) => {
var symbol_reader = reader.module.symbol_reader;
if (symbol_reader != null)
return symbol_reader.Read (provider);
return null;
});

return !collection.IsNullOrEmpty ();
}

public static Collection<CustomDebugInformation> GetCustomDebugInformations (
this ICustomDebugInformationProvider self,
ref Collection<CustomDebugInformation> collection,
ModuleDefinition module)
{
if (module.HasImage ())
module.Read (ref collection, self, (provider, reader) => {
var symbol_reader = reader.module.symbol_reader;
if (symbol_reader != null)
return symbol_reader.Read (self);
return null;
});

Interlocked.CompareExchange (ref collection, new Collection<CustomDebugInformation> (), null);
return collection;
}
}
}
24 changes: 2 additions & 22 deletions Mono.Cecil/TypeDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -292,32 +292,12 @@ public bool HasCustomDebugInformations {
if (custom_infos != null)
return custom_infos.Count > 0;

if (module.HasImage ())
module.Read (this, (provider, reader) => {
var symbol_reader = reader.module.symbol_reader;
if (symbol_reader != null)
custom_infos = symbol_reader.Read (provider);
});

return !custom_infos.IsNullOrEmpty ();
return this.GetHasCustomDebugInformations (ref custom_infos, Module);
}
}

public Collection<CustomDebugInformation> CustomDebugInformations {
get {
if (custom_infos != null)
return custom_infos;

if (module.HasImage ())
module.Read (this, (provider, reader) => {
var symbol_reader = reader.module.symbol_reader;
if (symbol_reader != null)
custom_infos = symbol_reader.Read (provider);
});

Interlocked.CompareExchange (ref custom_infos, new Collection<CustomDebugInformation> (), null);
return custom_infos;
}
get { return custom_infos ?? (this.GetCustomDebugInformations (ref custom_infos, module)); }
}

#region TypeAttributes
Expand Down

0 comments on commit e533f35

Please sign in to comment.