I’m working on a project where I need to extend WebClient for a custom implementation, MyWebClient.
I also need to make sure that MyWebClient is the only version that’s implemented by any developer on the project and no one uses the base WebClient class.
Is it possible to prevent the usage of WebClient, considering it’s not code that I have access to?
Depending on the features of
WebClientyou need, you could consider implementingMyWebClientas proxy that exposes only the methods you allow to be used from aWebClientmember.Example:
After, you will need a dedicated ctor and a maybe a factory to instantiate
MyWebClientproperly.This won’t prevent your developers from using
WebClientwhich would be far too difficult (see @gdoron suggestion, for instance), but will help avoiding its usage by mistake.Edit:
From your last comment, I think that all you need is a Factory that will set the User Agent for all your
WebClientinstances.Then, depending on your organization, you will need a strong communication about its usage (and maybe a search tool to look for
new WebClient()in your projects).