Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: allow reference handling for generic and runtime target type map…
…ping methods
- Loading branch information
Showing
23 changed files
with
435 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/Riok.Mapperly/Descriptors/Mappings/MappingBodyBuildingPriority.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace Riok.Mapperly.Descriptors.Mappings; | ||
|
||
/// <summary> | ||
/// When to build the body of this mapping. | ||
/// The body of mappings with a higher priority | ||
/// is built before the bodies of mappings with a lower priority. | ||
/// </summary> | ||
public enum MappingBodyBuildingPriority | ||
{ | ||
AfterUserMappings, | ||
Default, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/Riok.Mapperly/Descriptors/Mappings/UserMappings/IDelegateUserMapping.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
namespace Riok.Mapperly.Descriptors.Mappings.UserMappings; | ||
|
||
/// <summary> | ||
/// A delegated user mapping. | ||
/// </summary> | ||
public interface IDelegateUserMapping : IUserMapping | ||
{ | ||
/// <summary> | ||
/// Gets the delegate mapping or <c>null</c> if none is set (yet). | ||
/// </summary> | ||
ITypeMapping? DelegateMapping { get; } | ||
|
||
/// <summary> | ||
/// Sets the delegate mapping. | ||
/// </summary> | ||
/// <param name="mapping">The mapping.</param> | ||
void SetDelegateMapping(ITypeMapping mapping); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
namespace Riok.Mapperly.Helpers; | ||
|
||
/// <summary> | ||
/// A simple implementation of a priority queue. | ||
/// </summary> | ||
/// <typeparam name="TElement">The type of the elements.</typeparam> | ||
/// <typeparam name="TPriority">The priority of an element.</typeparam> | ||
public class PriorityQueue<TElement, TPriority> | ||
{ | ||
private readonly Dictionary<TPriority, Queue<TElement>> _nodes = new(); | ||
private readonly SortedSet<TPriority> _knownPriorities = new(); | ||
|
||
public void Enqueue(TElement element, TPriority priority) | ||
{ | ||
if (_nodes.TryGetValue(priority, out var node)) | ||
{ | ||
node.Enqueue(element); | ||
return; | ||
} | ||
|
||
var queue = new Queue<TElement>(); | ||
queue.Enqueue(element); | ||
_nodes[priority] = queue; | ||
_knownPriorities.Add(priority); | ||
} | ||
|
||
/// <summary> | ||
/// Dequeues all nodes. | ||
/// The nodes with the highest priority are returned first ordered in a FIFO fashion. | ||
/// Items added while this operation is in progress are also considered. | ||
/// </summary> | ||
/// <returns>An enumerable with all items.</returns> | ||
public IEnumerable<TElement> DequeueAll() | ||
{ | ||
while (_knownPriorities.Count > 0) | ||
{ | ||
var priority = _knownPriorities.Max; | ||
var queue = _nodes[priority]; | ||
var item = queue.Dequeue(); | ||
|
||
if (queue.Count == 0) | ||
{ | ||
_nodes.Remove(priority); | ||
_knownPriorities.Remove(priority); | ||
} | ||
|
||
yield return item; | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
namespace Riok.Mapperly.Tests.Helpers; | ||
|
||
public class PriorityQueueTest | ||
{ | ||
[Fact] | ||
public void EnqueueAndDequeueAllShouldWork() | ||
{ | ||
var queue = new Mapperly.Helpers.PriorityQueue<char, int>(); | ||
queue.Enqueue('C', 1); | ||
queue.Enqueue('A', 3); | ||
queue.Enqueue('B', 2); | ||
|
||
var index = 0; | ||
foreach (var item in queue.DequeueAll()) | ||
{ | ||
var expectedValue = (char)('A' + index); | ||
item.Should().Be(expectedValue); | ||
|
||
// enqueue during dequeue | ||
if (index == 2) | ||
{ | ||
queue.Enqueue('E', 0); | ||
queue.Enqueue('D', 1); | ||
queue.Enqueue('F', 0); | ||
} | ||
|
||
index++; | ||
} | ||
|
||
index.Should().Be(6); | ||
} | ||
} |
Oops, something went wrong.