Skip to content

Commit

Permalink
name changes and context property in the cloning reference importer
Browse files Browse the repository at this point in the history
  • Loading branch information
ds5678 committed Mar 30, 2022
1 parent bc688fd commit b5ac446
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ namespace AsmResolver.DotNet.Cloning
/// </summary>
public class CloneContextAwareReferenceImporter : ReferenceImporter
{
/// <summary>
/// The working space for this member cloning procedure.
/// </summary>
protected readonly MemberCloneContext _context;
private readonly MemberCloneContext _context;

/// <summary>
/// Creates a new instance of the <see cref="CloneContextAwareReferenceImporter"/> class.
Expand All @@ -20,6 +17,11 @@ public CloneContextAwareReferenceImporter(MemberCloneContext context)
_context = context;
}

/// <summary>
/// The working space for this member cloning procedure.
/// </summary>
protected MemberCloneContext Context => _context;

/// <inheritdoc />
protected override ITypeDefOrRef ImportType(TypeDefinition type)
{
Expand Down
6 changes: 3 additions & 3 deletions src/AsmResolver.DotNet/Cloning/MemberCloneContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ public class MemberCloneContext
/// Creates a new instance of the <see cref="MemberCloneContext"/> class.
/// </summary>
/// <param name="module">The target module to copy the cloned members into.</param>
/// <param name="importerInstantiator">The instantiator for creating the reference importer</param>
/// <param name="importerFactory">The factory for creating the reference importer</param>
public MemberCloneContext(ModuleDefinition module,
Func<MemberCloneContext, CloneContextAwareReferenceImporter>? importerInstantiator)
Func<MemberCloneContext, CloneContextAwareReferenceImporter>? importerFactory)
{
Module = module ?? throw new ArgumentNullException(nameof(module));
Importer = importerInstantiator?.Invoke(this) ?? new CloneContextAwareReferenceImporter(this);
Importer = importerFactory?.Invoke(this) ?? new CloneContextAwareReferenceImporter(this);
}

/// <summary>
Expand Down
10 changes: 5 additions & 5 deletions src/AsmResolver.DotNet/Cloning/MemberCloner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace AsmResolver.DotNet.Cloning
/// </remarks>
public partial class MemberCloner
{
private readonly Func<MemberCloneContext, CloneContextAwareReferenceImporter>? _importerInstantiator;
private readonly Func<MemberCloneContext, CloneContextAwareReferenceImporter>? _importerFactory;
private readonly ModuleDefinition _targetModule;

private readonly HashSet<TypeDefinition> _typesToClone = new();
Expand All @@ -36,12 +36,12 @@ public partial class MemberCloner
/// Creates a new instance of the <see cref="MemberCloner"/> class.
/// </summary>
/// <param name="targetModule">The target module to copy the members into.</param>
/// <param name="importerInstantiator">The instantiator for creating the reference importer</param>
/// <param name="importerFactory">The factory for creating the reference importer</param>
public MemberCloner(ModuleDefinition targetModule,
Func<MemberCloneContext, CloneContextAwareReferenceImporter>? importerInstantiator)
Func<MemberCloneContext, CloneContextAwareReferenceImporter>? importerFactory)
{
_targetModule = targetModule ?? throw new ArgumentNullException(nameof(targetModule));
_importerInstantiator = importerInstantiator;
_importerFactory = importerFactory;
}

/// <summary>
Expand Down Expand Up @@ -230,7 +230,7 @@ public MemberCloner Include(EventDefinition @event)
/// <returns>An object representing the result of the cloning process.</returns>
public MemberCloneResult Clone()
{
var context = new MemberCloneContext(_targetModule, _importerInstantiator);
var context = new MemberCloneContext(_targetModule, _importerFactory);

CreateMemberStubs(context);
DeepCopyMembers(context);
Expand Down

0 comments on commit b5ac446

Please sign in to comment.