Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to handle disposable objects? #226

Open
vyeghikyan-st opened this issue Oct 23, 2024 · 0 comments
Open

How to handle disposable objects? #226

vyeghikyan-st opened this issue Oct 23, 2024 · 0 comments

Comments

@vyeghikyan-st
Copy link

Let us have a class

public class MyClass{
  // Some methods, variables and constructors
  
  public Result<Stream> OpenStream() {
   // Implementation
  }

}

The only pattern I can think of for handling the returned object is as follows:

var instance = new MyClass(..);

var streamReasult = instance.OpenStream();

if(streamResult.IsFailed){
  return Result.Fail<...>(...);
}

try{
  // Do my stuff with the stream
}
finally{
  streamResult.Value.Dispose();
}

Is there a better way?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant