microsoft / vs-servicehub

The service broker libraries used by Visual Studio to exchange intra- and inter-process services
MIT License
20 stars 8 forks source link

Allow public access to ServiceJsonRpcDescriptor.CreateFormatter #213

Closed matteo-prosperi closed 3 months ago

matteo-prosperi commented 3 months ago

There are current implementations that wrap an existing ServiceJsonRpcDescriptor into another ServiceJsonRpcDescriptor-derived class. These implementations need to call CreateFormatter on the inner descriptor and they currently use reflection to do so. Unfortunately CreateFormatter is protected internal, so it cannot be made public without breaking the compilation of extended classes that are overriding this method. For this reason, I propose creating a new public method to make the CreateFormatter capability publicly accessible.

AArnott commented 3 months ago

As I suspected, we already have a pattern to fix this. Have you seen the DelegatingServiceJsonRpcDescriptor class? When you are wrapping another descriptor with a custom one, your custom one is supposed to derive from DelegatingServiceJsonRpcDescriptor, which lets you call your own CreateFormatter method and it invokes the inner one.