Struct TypeNullability
- Namespace
- LfrlAnvil
- Assembly
- LfrlAnvil.Core.dll
Represents detailed information about Type nullability.
public readonly struct TypeNullability : IEquatable<TypeNullability>
- Implements
- Inherited Members
- Extension Methods
Properties
ActualType
Specifies the actual Type.
public Type ActualType { get; }
Property Value
IsNullable
Specifies whether or not the ActualType is nullable.
public bool IsNullable { get; }
Property Value
UnderlyingType
Specifies the underlying Type. Will not be equal to ActualType only for nullable value types.
public Type UnderlyingType { get; }
Property Value
Methods
Create(Type, bool)
Creates a new TypeNullability instance.
[Pure]
public static TypeNullability Create(Type type, bool isNullable = false)
Parameters
type
TypeSource type.
isNullable
boolSpecifies whether or not the result should be nullable. Equal to false by default. Will be ignored for nullable value types.
Returns
- TypeNullability
New TypeNullability instance.
Create<T>(bool)
Creates a new TypeNullability instance.
[Pure]
public static TypeNullability Create<T>(bool isNullable = false) where T : notnull
Parameters
isNullable
boolSpecifies whether or not the result should be nullable. Equal to false by default.
Returns
- TypeNullability
New TypeNullability instance.
Type Parameters
T
Underlying type.
Equals(TypeNullability)
Indicates whether the current object is equal to another object of the same type.
[Pure]
public bool Equals(TypeNullability other)
Parameters
other
TypeNullabilityAn object to compare with this object.
Returns
Equals(object?)
Indicates whether this instance and a specified object are equal.
[Pure]
public override bool Equals(object? obj)
Parameters
obj
objectThe object to compare with the current instance.
Returns
- bool
true if
obj
and this instance are the same type and represent the same value; otherwise, false.
GetCommonType(TypeNullability?, TypeNullability?)
Returns a common TypeNullability instance for two instances.
[Pure]
public static TypeNullability? GetCommonType(TypeNullability? left, TypeNullability? right)
Parameters
left
TypeNullability?First type nullability.
right
TypeNullability?Second type nullability.
Returns
- TypeNullability?
null when
left
is null orright
is null or UnderlyingType properties are not equal, otherwiseleft
when it is nullable, otherwiseright
.
GetCommonTypeWith(TypeNullability?)
Returns a common TypeNullability instance for this instance and the provided other
.
[Pure]
public TypeNullability? GetCommonTypeWith(TypeNullability? other)
Parameters
other
TypeNullability?Other type nullability.
Returns
- TypeNullability?
null when
other
is null or UnderlyingType properties are not equal, otherwise this when it is nullable, otherwiseother
.
GetHashCode()
Returns the hash code for this instance.
[Pure]
public override int GetHashCode()
Returns
- int
A 32-bit signed integer that is the hash code for this instance.
MakeNullable()
Creates a new TypeNullability instance from this instance with IsNullable set to true.
[Pure]
public TypeNullability MakeNullable()
Returns
- TypeNullability
New TypeNullability instance.
MakeRequired()
Creates a new TypeNullability instance from this instance with IsNullable set to false.
[Pure]
public TypeNullability MakeRequired()
Returns
- TypeNullability
New TypeNullability instance.
ToString()
Returns a string representation of this TypeNullability instance.
[Pure]
public override string ToString()
Returns
- string
String representation.
Operators
operator ==(TypeNullability, TypeNullability)
Checks if a
is equal to b
.
[Pure]
public static bool operator ==(TypeNullability a, TypeNullability b)
Parameters
a
TypeNullabilityFirst operand.
b
TypeNullabilitySecond operand.
Returns
- bool
true when operands are equal, otherwise false.
operator !=(TypeNullability, TypeNullability)
Checks if a
is not equal to b
.
[Pure]
public static bool operator !=(TypeNullability a, TypeNullability b)
Parameters
a
TypeNullabilityFirst operand.
b
TypeNullabilitySecond operand.
Returns
- bool
true when operands are not equal, otherwise false.