Table of Contents

Struct NullableRef<T>

Namespace
Sdl3Sharp.Utilities
Assembly
Sdl3Sharp.dll

Represents a explicitly nullable reference

public readonly ref struct NullableRef<T> : IEquatable<NullableRef<T>>, IEquatable<NullableRefReadOnly<T>>

Type Parameters

T

The type of value the NullableRef<T> represents a reference of

Implements
Inherited Members

Remarks

To construct a NullableRef<T> that represents a null-reference, use Null or default(NullableRef<T>).

Constructors

NullableRef(ref T)

Represents a explicitly nullable reference

public NullableRef(ref T target)

Parameters

target T

An actual reference to the value of type T the NullableRef<T> should represent a reference to

Remarks

To construct a NullableRef<T> that represents a null-reference, use Null or default(NullableRef<T>).

Properties

HasTarget

Gets a value indicating whether this NullableRef<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 NullableRef<T> does not represent a null-reference

IsNull

Gets a value indicating whether this NullableRef<T> does represent a null-reference

public bool IsNull { get; }

Property Value

bool

A value indicating whether this NullableRef<T> does represent a null-reference

Remarks

If the value of this property is true, the Target property can't be safely dereferenced.

Null

Gets a NullableRef<T> that represents a null-reference

public static NullableRef<T> Null { get; }

Property Value

NullableRef<T>

A NullableRef<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 reference to the value of type T this NullableRef<T> references

public ref T Target { get; }

Property Value

T

An actual reference to the value of type T this NullableRef<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 NullableRef<T> represents a null-reference

Methods

Equals(NullableRefReadOnly<T>)

Indicates whether the current object is equal to another object of the same type.

public bool Equals(NullableRefReadOnly<T> other)

Parameters

other NullableRefReadOnly<T>

An object to compare with this object.

Returns

bool

true if the current object is equal to the other parameter; otherwise, false.

Equals(NullableRef<T>)

Indicates whether the current object is equal to another object of the same type.

public bool Equals(NullableRef<T> other)

Parameters

other NullableRef<T>

An object to compare with this object.

Returns

bool

true if the current object is equal to the other parameter; otherwise, false.

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

obj object

Not 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 reference to the value of type T this NullableRef<T> references, without validating if it's safely dereferencable

public ref readonly T GetReferenceOrNull()

Returns

T

An actual reference to the value of type T this NullableRef<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 ==(NullableRef<T>, NullableRefReadOnly<T>)

Compares two values to determine equality.

public static bool operator ==(NullableRef<T> left, NullableRefReadOnly<T> right)

Parameters

left NullableRef<T>

The value to compare with right.

right NullableRefReadOnly<T>

The value to compare with left.

Returns

bool

true if left is equal to right; otherwise, false.

operator ==(NullableRef<T>, NullableRef<T>)

Compares two values to determine equality.

public static bool operator ==(NullableRef<T> left, NullableRef<T> right)

Parameters

left NullableRef<T>

The value to compare with right.

right NullableRef<T>

The value to compare with left.

Returns

bool

true if left is equal to right; otherwise, false.

implicit operator NullableRefReadOnly<T>(NullableRef<T>)

public static implicit operator NullableRefReadOnly<T>(NullableRef<T> nullableRef)

Parameters

nullableRef NullableRef<T>

The NullableRef<T> to convert

Returns

NullableRefReadOnly<T>

Remarks

The resulting NullableRefReadOnly<T> will reference the same value of T nullableRef references. This also means that, if nullableRef represents a null-reference, the resulting NullableRefReadOnly<T> will represent a null-reference.

operator !=(NullableRef<T>, NullableRefReadOnly<T>)

Compares two values to determine inequality.

public static bool operator !=(NullableRef<T> left, NullableRefReadOnly<T> right)

Parameters

left NullableRef<T>

The value to compare with right.

right NullableRefReadOnly<T>

The value to compare with left.

Returns

bool

true if left is not equal to right; otherwise, false.

operator !=(NullableRef<T>, NullableRef<T>)

Compares two values to determine inequality.

public static bool operator !=(NullableRef<T> left, NullableRef<T> right)

Parameters

left NullableRef<T>

The value to compare with right.

right NullableRef<T>

The value to compare with left.

Returns

bool

true if left is not equal to right; otherwise, false.