How to call a extension method with Out Parameters within LINQ Query and use Out Values?

kailash
kailash
Member
12 Points
1 Posts

I have following extension method in fhir R4 model in .net nuget package as:

Hl7.Fhir.Model.Resource.TryDeriveResourceType(out ResourceType resourceType);

It's fine when using it as single object but when try to compare in LINQ query - how to compare it. I'm trying something like:

var patientResource = bundles.Entry.
FirstOrDefault(x => x.TryDeriveResourceType(out ResourceType resourceType) == ResourceType.Patient).Resource as Hl7.Fhir.Model.Patient;
            

But it's wrong and getting compile time error.

Is there any way to compare resource type with output the of the abobe extension method?

 

Views: 258
Total Answered: 1
Total Marked As Answer: 1
Posted On: 13-Sep-2023 01:08

Share:   fb twitter linkedin
Answers
Smith
Smith
Participant
2768 Points
76 Posts
         

Use following code to delegate encapsulation:

private readonly Func<Hl7.Fhir.Model.Resource, ResourceType> funResourceType = f =>
        {
            f.TryDeriveResourceType(out ResourceType resourceType);
            return resourceType;
        };

try to use as:

var patientResource = bundles.Entry.
FirstOrDefault(x => funResourceType(x.Resource) == ResourceType.Patient).Resource as Hl7.Fhir.Model.Patient;
Posted On: 14-Sep-2023 00:03
Thanks.
 - kailash  20-Sep-2023 04:20
 Log In to Chat