I have the follow code but it is awkward. How could I better structure it? Do I have to make my consuming class implement IDisposable and conditionally construct the network acc
If you repeat this pattern in many methods you can break out the pattern
protected void OptionalNetworkCall(Action action)
{
if (useNetworkAccess)
{
using (new Core.NetworkAccess(username, password, domain))
{
action();
}
}
else
{
action();
}
}
protected void ValidateExportDirectoryExists()
{
OptionalNetworkCall(CheckExportDirectoryExists);
}