Struct NullableRefReadOnly<T>
Represents a explicitly nullable read-only reference
public readonly ref struct NullableRefReadOnly<T>
Type Parameters
TThe type of value the NullableRefReadOnly<T> represents a reference of
- Inherited Members
Remarks
To construct a NullableRefReadOnly<T> that represents a null-reference, use Null or default(NullableRefReadOnly<.
T>)
Constructors
NullableRefReadOnly(ref readonly T)
Represents a explicitly nullable read-only reference
public NullableRefReadOnly(ref readonly T target)
Parameters
targetTAn actual read-only reference to the value of type
Tthe NullableRefReadOnly<T> should represent a reference to
Remarks
To construct a NullableRefReadOnly<T> that represents a null-reference, use Null or default(NullableRefReadOnly<.
T>)
Properties
HasTarget
Gets a value indicating whether this NullableRefReadOnly<T> does not represent a null-reference and the Target property can be safely dereferenced
public bool HasTarget { get; }
Property Value
- bool
A value indicating whether this NullableRefReadOnly<T> does not represent a
null-reference
IsNull
Gets a value indicating whether this NullableRefReadOnly<T> does represent a null-reference
public bool IsNull { get; }
Property Value
- bool
A value indicating whether this NullableRefReadOnly<T> does represent a
null-reference
Remarks
Null
Gets a NullableRefReadOnly<T> that represents a null-reference
public static NullableRefReadOnly<T> Null { get; }
Property Value
- NullableRefReadOnly<T>
A NullableRefReadOnly<T> that represents a
null-reference
Remarks
Do not try the dereference the returned reference from a call to GetReferenceOrNull() on the resulting value of this property!
Target
Gets an actual read-only reference to the value of type T this NullableRefReadOnly<T> references
public ref readonly T Target { get; }
Property Value
- T
An actual read-only reference to the value of type
Tthis NullableRefReadOnly<T> references
Remarks
If the value of the HasTarget property is false or the value of the IsNull property is true,
accessing this property will throw an InvalidOperationException.
Exceptions
- InvalidOperationException
The NullableRefReadOnly<T> represents a
null-reference
Methods
Equals(NullableRefReadOnly<T>)
public bool Equals(NullableRefReadOnly<T> other)
Parameters
otherNullableRefReadOnly<T>
Returns
Equals(NullableRef<T>)
public bool Equals(NullableRef<T> other)
Parameters
otherNullableRef<T>
Returns
Equals(object?)
Calls to this method are not supported
[Obsolete("Calls to this method are not supported. This method will always throw an exception. Use the \"Equals\" methods or the equality operators instead.")]
[DoesNotReturn]
public override bool Equals(object? obj)
Parameters
objobjectNot supported
Returns
- bool
Not supported
Exceptions
- NotSupportedException
always
GetHashCode()
Returns the hash code for this instance.
public override int GetHashCode()
Returns
- int
A 32-bit signed integer that is the hash code for this instance.
GetReferenceOrNull()
Gets an actual read-only reference to the value of type T this NullableRefReadOnly<T> references, without validating if it's safely dereferencable
public ref readonly T GetReferenceOrNull()
Returns
- T
An actual read-only reference to the value of type
Tthis NullableRefReadOnly<T> references
Remarks
This method does not validate if the represented reference is safely dereferencable! Users should check the value of the HasTarget property or the value of the IsNull property first, to determine if the result of this method is safe to dereference. Use with care!
Operators
operator ==(NullableRefReadOnly<T>, NullableRefReadOnly<T>)
Compares two values to determine equality.
public static bool operator ==(NullableRefReadOnly<T> left, NullableRefReadOnly<T> right)
Parameters
leftNullableRefReadOnly<T>The value to compare with
right.rightNullableRefReadOnly<T>The value to compare with
left.
Returns
operator ==(NullableRefReadOnly<T>, NullableRef<T>)
Compares two values to determine equality.
public static bool operator ==(NullableRefReadOnly<T> left, NullableRef<T> right)
Parameters
leftNullableRefReadOnly<T>The value to compare with
right.rightNullableRef<T>The value to compare with
left.
Returns
operator !=(NullableRefReadOnly<T>, NullableRefReadOnly<T>)
Compares two values to determine inequality.
public static bool operator !=(NullableRefReadOnly<T> left, NullableRefReadOnly<T> right)
Parameters
leftNullableRefReadOnly<T>The value to compare with
right.rightNullableRefReadOnly<T>The value to compare with
left.
Returns
operator !=(NullableRefReadOnly<T>, NullableRef<T>)
Compares two values to determine inequality.
public static bool operator !=(NullableRefReadOnly<T> left, NullableRef<T> right)
Parameters
leftNullableRefReadOnly<T>The value to compare with
right.rightNullableRef<T>The value to compare with
left.