-
Notifications
You must be signed in to change notification settings - Fork 345
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2845 from FirelyTeam/feature/scopednode-cache-dic…
…tionaries Scoped node cache overhaul
- Loading branch information
Showing
3 changed files
with
90 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace Hl7.Fhir.ElementModel; | ||
|
||
#nullable enable | ||
|
||
internal class ReferencedResourceCache : IEnumerable<ScopedNode.BundledResource> | ||
{ | ||
private Dictionary<string, ScopedNode?> _items; | ||
|
||
public ReferencedResourceCache(IEnumerable<KeyValuePair<string, ScopedNode?>> items) | ||
{ | ||
_items = new Dictionary<string, ScopedNode?>(); | ||
foreach (var item in items) | ||
{ | ||
_items.Add(item.Key, item.Value); | ||
} | ||
} | ||
|
||
internal IEnumerable<ScopedNode> Resources => _items.Values.OfType<ScopedNode>(); | ||
|
||
internal ScopedNode? ResolveReference(string reference) | ||
{ | ||
return _items.TryGetValue(reference, out var node) ? node : null; | ||
} | ||
|
||
public IEnumerator<ScopedNode.BundledResource> GetEnumerator() => _items.Select(i => new ScopedNode.BundledResource(i.Key, i.Value)).GetEnumerator(); | ||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); | ||
} | ||
|
||
#nullable restore |
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