Stream: dotnet
Topic: Find all instances of a type
Mads Øigård (Apr 24 2020 at 09:45):
Hey, Is there any existing method for finding all elements of a type? In my case I have to find every ResourceReference in any given resource.
Mirjam Baltus (Apr 24 2020 at 13:58):
Yes, there is, but you will need to add the Hl7.Fhir.ElementModel package to convert your resource to a TypedElement. You can then select all elements of type reference and parse them into ResourceReference objects. Here's an example, with res
being your given resource.
var refs = res.ToTypedElement().Descendants().Where(e => e.InstanceType == "Reference"); foreach (var r in refs) { // use r.ParseResourceReference() to work with the ResourceReference }
Mads Øigård (Apr 27 2020 at 06:31):
Thank you! This is just what I needed.
Last updated: Apr 12 2022 at 19:14 UTC