Class DisposableOptions
- Namespace
- Cuemon
- Assembly
- Cuemon.Kernel.dll
Configuration options for IDisposable.
public class DisposableOptions : IParameterObject
- Inheritance
-
DisposableOptions
- Implements
- Derived
Examples
The following example demonstrates how to use
using System;
using Cuemon;
namespace Contoso.IO;
public sealed class DisposableOptionsExample
{
public static void Run()
{
var resource = new TrackedDisposable();
var options = new DisposableOptions
{
LeaveOpen = true
};
DisposeWhenAllowed(resource, options);
Console.WriteLine($"Disposed after leave-open: {resource.IsDisposed}");
options.LeaveOpen = false;
DisposeWhenAllowed(resource, options);
Console.WriteLine($"Disposed after close: {resource.IsDisposed}");
}
private static void DisposeWhenAllowed(TrackedDisposable resource, DisposableOptions options)
{
if (!options.LeaveOpen)
{
resource.Dispose();
}
}
private sealed class TrackedDisposable : IDisposable
{
public bool IsDisposed { get; private set; }
public void Dispose()
{
IsDisposed = true;
}
}
}
Constructors
DisposableOptions()
Initializes a new instance of the DisposableOptions class.
public DisposableOptions()
Remarks
The following table shows the initial property values for an instance of DisposableOptions.
| Property | Initial Value |
|---|---|
| LeaveOpen | false |
Properties
LeaveOpen
Gets or sets a value indicating whether a disposable object should bypass the mechanism for releasing unmanaged resources. Default is false.
public bool LeaveOpen { get; set; }
Property Value
- bool
trueif a disposable object should bypass the mechanism for releasing unmanaged resources; otherwise,false.