You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@katy-hughes-cko , not sure if I'm missing something, but this works for me:
using OneOf;PaymentResponsepaymentProcessed=new PaymentProcessed();varresult=await DoThingAsync(paymentProcessed);
Console.WriteLine(result);staticasyncTask<string>DoThingAsync<T>(Tresponse,CancellationTokencancellationToken=default){if(response is PaymentResponse _){returnawait Task.FromResult("response was a PaymentResponse");}returnawait Task.FromResult("Unknown type of response");}publicclassPaymentResponse:OneOfBase<PaymentProcessed,PaymentAccepted,ActionFailed>{privatePaymentResponse(OneOf<PaymentProcessed,PaymentAccepted,ActionFailed>_):base(_){}publicstaticimplicitoperator PaymentResponse(PaymentProcessed_)=>new(_);publicstaticimplicitoperator PaymentResponse(PaymentAccepted_)=>new(_);publicstaticimplicitoperator PaymentResponse(ActionFailed_)=>new(_);}publicclassPaymentProcessed{}publicclassPaymentAccepted{}publicclassActionFailed{}
Hi!
I'm trying to understand how I can use pattern matching with reusable OneOfBase types.
The
TResponse
generic parameter here is of typePaymentProcessed
, but it evaluatesresponse is PaymentResponse paymentResponse
asfalse
In order for this to work I have to continue to use the OneOf<> full type. Thanks for any help!
The text was updated successfully, but these errors were encountered: