C# conditional using block statement

后端 未结 10 1912
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-02 07:25

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

10条回答
  •  感动是毒
    2021-02-02 08:10

    protected void ValidateExportDirectoryExists()
    {
          var access = useNetworkAccess
              ? new Core.NetworkAccess(username, password, domain)
                : null;
    
          using (access)
          {
              CheckExportDirectoryExists();
          }
    }
    

提交回复
热议问题