SafeHandleValue Struct
A disposable struct that safely holds a reference to a SafeHandle and its underlying handle value. Automatically increments the reference count on creation and decrements it on disposal.
public readonly struct SafeHandleValue : IDisposableRemarks
The copies of a value share the reference: disposing any of them releases it, once.
Example
using var safeHandle = File.OpenHandle(Path.GetTempFileName(), FileMode.Open, FileAccess.Read, FileShare.None, FileOptions.DeleteOnClose);
// The SafeHandle cannot be released while the scope is alive
using var scope = safeHandle.CreateHandleScope();
nint handle = scope.Value;
Assert.NotEqual(0, handle); // Use handle safely, for instance in a P/Invoke call- Implements
Constructors
| Name | Description |
|---|---|
| SafeHandleValue(SafeHandle) |
SafeHandleValue(SafeHandle)
SafeHandleValue.cspublic SafeHandleValue(SafeHandle safeHandle)Parameters
safeHandleSafeHandle
No documentation is available.
Properties
| Name | Description |
|---|---|
| HasValue | Gets a value indicating whether the handle has a valid value. |
| Value | Gets the underlying handle value. |
HasValue
SafeHandleValue.csValue
SafeHandleValue.csMethods
| Name | Description |
|---|---|
| Dispose() |
Dispose()
SafeHandleValue.cspublic void Dispose()No documentation is available.
Operators
| Name | Description |
|---|---|
| implicit operator nint(SafeHandleValue) |
implicit operator nint(SafeHandleValue)
SafeHandleValue.cspublic static implicit operator nint(SafeHandleValue handle)No documentation is available.