0

I use a web service in a C# project. I test the project both online and on localhost. I have code like:

 //var proxy = new PanoNestWebsite.ScheduleImagePanonest.ScheduleImageProcessingClient();
 //var s = new ScheduleImagePanonest.ScheduleImageProcessing();
 var proxy = new ScheduleImageLocal.ScheduleImageProcessingClient();
 var s = new ScheduleImageLocal.ScheduleImageProcessing();

For example, If I want to deploy it online I uncomment the first two lines, and comment the last two.

But I have much more changes to make, and I don't like commenting and uncommenting all lines. How can I use proprocessing directives to define a variable like: IsLocal and I just set it to true to include the local code, or to false to include the server code? How can I write something like this?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Ryan
  • 5,456
  • 25
  • 71
  • 129

2 Answers2

3

If this is the kind of thing that you're dealing with, I'd recommend an alternative approach, possibly some IOC/DI where both of these classes implement an interface, and you configure in your app.config/web.config which type to point to it.

So instead of

var proxy = new ScheduleImageLocal.ScheduleImageProcessingClient();

you'd instead do

var proxy = IoCFactory.Resolve<IScheduleImagingProcessingClient>();

or something to that effect, however your library works.

If you use Unity, you would point the IScheduleImagingProcessingClient interface to a concrete type in your config file.

Joe Enos
  • 39,478
  • 11
  • 80
  • 136
1

You can use the project properties to define values or #define SOME_KEY then:

#if KEY

    ... Code goes here

#endif
Mithrandir
  • 24,869
  • 6
  • 50
  • 66