I have a generated code with partial method
{
...
partial void InterceptOperationCall(IOperationContext context);
...
async Task SomeMethod()
{
InterceptOperationCall(cntx);
await LongOperation(cntx);
}
}
and handwrited partial
{
partial void InterceptOperationCall(IOperationContext context)
{
}
}
I need to do async calls inside InterceptOperationCall
Does any one knows some way to workaround partial method restrictions?
Another words: I want to do InterceptOperationCall asynchronously and guaranteed before long operation, at the same time i want to optionaly declare body of this method in another file.
UPD as workaround solution i chose to:
Castle.DynamicProxy
) and intercept with
AsyncInterceptorBase
from (Nito.AsyncEx
)Any way I keep looking for better solution, and if someone know another ways to provide optional ability to wrap async calls with somoe async logic please help me.
In order to create a partial method, it must be declared first(like an abstract method), with a signature only and no definition. After it is declared, its body can be defined in the same component or different component of the partial class/struct . A partial method is implicitly private.
With async void methods, there is no Task object, so any exceptions thrown out of an async void method will be raised directly on the SynchronizationContext that was active when the async void method started. Figure 2 illustrates that exceptions thrown from async void methods can't be caught naturally.
cs partial class A { partial void Method(); } in class2. cs partial class A { partial void Method() { Console. WriteLine("Hello World"); } } now in class3. cs class MainClass { static void Main() { A obj = new A(); obj.
If a method has no async operations inside it there's no benefit in making it async . You should only have async methods where you have an async operation (I/O, DB, etc.). If your application has a lot of these I/O methods and they spread throughout your code base, that's not a bad thing.
You can use the async keyword when implementing the partial method.
So
async partial void InterceptOperationCall(IOperationContext context) {
}
should be no problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With