custom extension method polly #1044
Replies: 3 comments
-
|
You can’t write extension methods for the type statically, only an instance of that type. This won’t work: Policy.MyExtensionMethod();This will: var myPolicy = ...;
myPolicy.MyExtensionMethod();You’ll need to either start from a custom static class: var policy = MyPolicy.HandleAndRetry(...);Or extend the policy builder and extend from the second line of what you’re trying to do in your extension method. |
Beta Was this translation helpful? Give feedback.
-
|
it worked, creating the extension method from the PolicyBuilder, |
Beta Was this translation helpful? Give feedback.
-
|
As a side-note if (policyResult.FinalException != null)
throw policyResult.FinalException;
return policyResult;IMHO it does not make too much sense. If the execution fails then it will throw an exception. If it succeeds then you have to unwrap the result from the I would suggest to simply prefer |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I trying to create my on extension method to policy, is this possible ?
Because I'm failing miserably
using the extension

creating

Beta Was this translation helpful? Give feedback.
All reactions