I don’t always have a network connection when I’m coding/testing as I code when I travel (train, flights, etc). I would like to setup a precompiler condition to skip some code if a connection is not detected. Sure I can just deal with the errors, but I don’t want that logic as part of the code-base. Is there a way to do this? Perhaps with Macros?
Example:
#if ConnectedToNetwork
PerformFunctionThatRequiresNetwork();
#else
DoSomethingElseThatDoentRequireNetwork();
#endif
Do you know when you have no network? If so, why not set up a new build definition that has the “no network” setting and use it when debugging where you know you do not have a network? I think this would be far easier, since this is a development issue, than creating a programmatic precompile step.
As for “I must do this in precompile”, I would separate out the code that calls network and compile a “non network” version. That can easily be swapped during the compilation step for debug and get around the issue.
The other question is whether this is better served at runtime. Should users also have the networking bits turned off when they have no network, or do you merely handle this eventuality through exceptions?