[C#] Enable nullability for variant structs

This commit is contained in:
Thaddeus Crews 2023-10-07 14:37:13 -05:00
parent b94eb58d35
commit db7a643e1c
No known key found for this signature in database
GPG Key ID: 62181B86FE9E5D84
17 changed files with 86 additions and 35 deletions

View File

@ -1,6 +1,9 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
#nullable enable
namespace Godot
{
/// <summary>
@ -689,7 +692,7 @@ namespace Godot
/// </summary>
/// <param name="obj">The object to compare with.</param>
/// <returns>Whether or not the AABB and the object are equal.</returns>
public override readonly bool Equals(object obj)
public override readonly bool Equals([NotNullWhen(true)] object? obj)
{
return obj is Aabb other && Equals(other);
}
@ -739,7 +742,7 @@ namespace Godot
/// Converts this <see cref="Aabb"/> to a string with the given <paramref name="format"/>.
/// </summary>
/// <returns>A string representation of this AABB.</returns>
public readonly string ToString(string format)
public readonly string ToString(string? format)
{
return $"{_position.ToString(format)}, {_size.ToString(format)}";
}

View File

@ -1,7 +1,10 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using System.ComponentModel;
#nullable enable
namespace Godot
{
/// <summary>
@ -1090,7 +1093,7 @@ namespace Godot
/// </summary>
/// <param name="obj">The object to compare with.</param>
/// <returns>Whether or not the basis matrix and the object are exactly equal.</returns>
public override readonly bool Equals(object obj)
public override readonly bool Equals([NotNullWhen(true)] object? obj)
{
return obj is Basis other && Equals(other);
}
@ -1140,7 +1143,7 @@ namespace Godot
/// Converts this <see cref="Basis"/> to a string with the given <paramref name="format"/>.
/// </summary>
/// <returns>A string representation of this basis.</returns>
public readonly string ToString(string format)
public readonly string ToString(string? format)
{
return $"[X: {X.ToString(format)}, Y: {Y.ToString(format)}, Z: {Z.ToString(format)}]";
}

View File

@ -1,7 +1,10 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using Godot.NativeInterop;
#nullable enable
namespace Godot
{
/// <summary>
@ -1274,7 +1277,7 @@ namespace Godot
/// </summary>
/// <param name="obj">The other object to compare.</param>
/// <returns>Whether or not the color and the other object are equal.</returns>
public override readonly bool Equals(object obj)
public override readonly bool Equals([NotNullWhen(true)] object? obj)
{
return obj is Color other && Equals(other);
}
@ -1324,7 +1327,7 @@ namespace Godot
/// Converts this <see cref="Color"/> to a string with the given <paramref name="format"/>.
/// </summary>
/// <returns>A string representation of this color.</returns>
public readonly string ToString(string format)
public readonly string ToString(string? format)
{
return $"({R.ToString(format)}, {G.ToString(format)}, {B.ToString(format)}, {A.ToString(format)})";
}

View File

@ -1,6 +1,9 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
#nullable enable
namespace Godot
{
/// <summary>
@ -382,7 +385,7 @@ namespace Godot
/// </summary>
/// <param name="obj">The other object to compare.</param>
/// <returns>Whether or not the plane and the other object are exactly equal.</returns>
public override readonly bool Equals(object obj)
public override readonly bool Equals([NotNullWhen(true)] object? obj)
{
return obj is Plane other && Equals(other);
}
@ -430,7 +433,7 @@ namespace Godot
/// Converts this <see cref="Plane"/> to a string with the given <paramref name="format"/>.
/// </summary>
/// <returns>A string representation of this plane.</returns>
public readonly string ToString(string format)
public readonly string ToString(string? format)
{
return $"{_normal.ToString(format)}, {_d.ToString(format)}";
}

View File

@ -1,6 +1,9 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
#nullable enable
namespace Godot
{
/// <summary>
@ -586,7 +589,7 @@ namespace Godot
public readonly Vector2 GetFarPlaneHalfExtents()
{
var res = GetProjectionPlane(Planes.Far).Intersect3(GetProjectionPlane(Planes.Right), GetProjectionPlane(Planes.Top));
return new Vector2(res.Value.X, res.Value.Y);
return res is null ? default : new Vector2(res.Value.X, res.Value.Y);
}
/// <summary>
@ -597,7 +600,7 @@ namespace Godot
public readonly Vector2 GetViewportHalfExtents()
{
var res = GetProjectionPlane(Planes.Near).Intersect3(GetProjectionPlane(Planes.Right), GetProjectionPlane(Planes.Top));
return new Vector2(res.Value.X, res.Value.Y);
return res is null ? default : new Vector2(res.Value.X, res.Value.Y);
}
/// <summary>
@ -981,7 +984,7 @@ namespace Godot
/// </summary>
/// <param name="obj">The object to compare with.</param>
/// <returns>Whether or not the vector and the object are equal.</returns>
public override readonly bool Equals(object obj)
public override readonly bool Equals([NotNullWhen(true)] object? obj)
{
return obj is Projection other && Equals(other);
}
@ -1018,7 +1021,7 @@ namespace Godot
/// Converts this <see cref="Projection"/> to a string with the given <paramref name="format"/>.
/// </summary>
/// <returns>A string representation of this projection.</returns>
public readonly string ToString(string format)
public readonly string ToString(string? format)
{
return $"{X.X.ToString(format)}, {X.Y.ToString(format)}, {X.Z.ToString(format)}, {X.W.ToString(format)}\n" +
$"{Y.X.ToString(format)}, {Y.Y.ToString(format)}, {Y.Z.ToString(format)}, {Y.W.ToString(format)}\n" +

View File

@ -1,6 +1,9 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
#nullable enable
namespace Godot
{
/// <summary>
@ -769,7 +772,7 @@ namespace Godot
/// </summary>
/// <param name="obj">The other object to compare.</param>
/// <returns>Whether or not the quaternion and the other object are exactly equal.</returns>
public override readonly bool Equals(object obj)
public override readonly bool Equals([NotNullWhen(true)] object? obj)
{
return obj is Quaternion other && Equals(other);
}
@ -817,7 +820,7 @@ namespace Godot
/// Converts this <see cref="Quaternion"/> to a string with the given <paramref name="format"/>.
/// </summary>
/// <returns>A string representation of this quaternion.</returns>
public readonly string ToString(string format)
public readonly string ToString(string? format)
{
return $"({X.ToString(format)}, {Y.ToString(format)}, {Z.ToString(format)}, {W.ToString(format)})";
}

View File

@ -1,6 +1,9 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
#nullable enable
namespace Godot
{
/// <summary>
@ -427,7 +430,7 @@ namespace Godot
/// </summary>
/// <param name="obj">The other object to compare.</param>
/// <returns>Whether or not the rect and the other object are exactly equal.</returns>
public override readonly bool Equals(object obj)
public override readonly bool Equals([NotNullWhen(true)] object? obj)
{
return obj is Rect2 other && Equals(other);
}
@ -475,7 +478,7 @@ namespace Godot
/// Converts this <see cref="Rect2"/> to a string with the given <paramref name="format"/>.
/// </summary>
/// <returns>A string representation of this rect.</returns>
public readonly string ToString(string format)
public readonly string ToString(string? format)
{
return $"{_position.ToString(format)}, {_size.ToString(format)}";
}

View File

@ -1,6 +1,9 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
#nullable enable
namespace Godot
{
/// <summary>
@ -398,7 +401,7 @@ namespace Godot
/// </summary>
/// <param name="obj">The other object to compare.</param>
/// <returns>Whether or not the rect and the other object are equal.</returns>
public override readonly bool Equals(object obj)
public override readonly bool Equals([NotNullWhen(true)] object? obj)
{
return obj is Rect2I other && Equals(other);
}
@ -435,7 +438,7 @@ namespace Godot
/// Converts this <see cref="Rect2I"/> to a string with the given <paramref name="format"/>.
/// </summary>
/// <returns>A string representation of this rect.</returns>
public readonly string ToString(string format)
public readonly string ToString(string? format)
{
return $"{_position.ToString(format)}, {_size.ToString(format)}";
}

View File

@ -1,8 +1,11 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Godot.NativeInterop;
#nullable enable
namespace Godot
{
/// <summary>
@ -71,7 +74,7 @@ namespace Godot
/// </summary>
/// <param name="obj">The other object to compare.</param>
/// <returns>Whether or not the color and the other object are equal.</returns>
public override readonly bool Equals(object obj)
public override readonly bool Equals([NotNullWhen(true)] object? obj)
{
return obj is Rid other && Equals(other);
}

View File

@ -1,7 +1,10 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
#nullable enable
namespace Godot
{
/// <summary>
@ -606,7 +609,7 @@ namespace Godot
/// </summary>
/// <param name="obj">The object to compare with.</param>
/// <returns>Whether or not the transform and the object are exactly equal.</returns>
public override readonly bool Equals(object obj)
public override readonly bool Equals([NotNullWhen(true)] object? obj)
{
return obj is Transform2D other && Equals(other);
}
@ -656,7 +659,7 @@ namespace Godot
/// Converts this <see cref="Transform2D"/> to a string with the given <paramref name="format"/>.
/// </summary>
/// <returns>A string representation of this transform.</returns>
public readonly string ToString(string format)
public readonly string ToString(string? format)
{
return $"[X: {X.ToString(format)}, Y: {Y.ToString(format)}, O: {Origin.ToString(format)}]";
}

View File

@ -1,7 +1,10 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using System.ComponentModel;
#nullable enable
namespace Godot
{
/// <summary>
@ -630,7 +633,7 @@ namespace Godot
/// </summary>
/// <param name="obj">The object to compare with.</param>
/// <returns>Whether or not the transform and the object are exactly equal.</returns>
public override readonly bool Equals(object obj)
public override readonly bool Equals([NotNullWhen(true)] object? obj)
{
return obj is Transform3D other && Equals(other);
}
@ -680,7 +683,7 @@ namespace Godot
/// Converts this <see cref="Transform3D"/> to a string with the given <paramref name="format"/>.
/// </summary>
/// <returns>A string representation of this transform.</returns>
public readonly string ToString(string format)
public readonly string ToString(string? format)
{
return $"[X: {Basis.X.ToString(format)}, Y: {Basis.Y.ToString(format)}, Z: {Basis.Z.ToString(format)}, O: {Origin.ToString(format)}]";
}

View File

@ -1,6 +1,9 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
#nullable enable
namespace Godot
{
/// <summary>
@ -954,7 +957,7 @@ namespace Godot
/// </summary>
/// <param name="obj">The object to compare with.</param>
/// <returns>Whether or not the vector and the object are equal.</returns>
public override readonly bool Equals(object obj)
public override readonly bool Equals([NotNullWhen(true)] object? obj)
{
return obj is Vector2 other && Equals(other);
}
@ -1016,7 +1019,7 @@ namespace Godot
/// Converts this <see cref="Vector2"/> to a string with the given <paramref name="format"/>.
/// </summary>
/// <returns>A string representation of this vector.</returns>
public readonly string ToString(string format)
public readonly string ToString(string? format)
{
return $"({X.ToString(format)}, {Y.ToString(format)})";
}

View File

@ -1,6 +1,9 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
#nullable enable
namespace Godot
{
/// <summary>
@ -535,7 +538,7 @@ namespace Godot
/// </summary>
/// <param name="obj">The object to compare with.</param>
/// <returns>Whether or not the vector and the object are equal.</returns>
public override readonly bool Equals(object obj)
public override readonly bool Equals([NotNullWhen(true)] object? obj)
{
return obj is Vector2I other && Equals(other);
}
@ -572,7 +575,7 @@ namespace Godot
/// Converts this <see cref="Vector2I"/> to a string with the given <paramref name="format"/>.
/// </summary>
/// <returns>A string representation of this vector.</returns>
public readonly string ToString(string format)
public readonly string ToString(string? format)
{
return $"({X.ToString(format)}, {Y.ToString(format)})";
}

View File

@ -1,6 +1,9 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
#nullable enable
namespace Godot
{
/// <summary>
@ -1056,7 +1059,7 @@ namespace Godot
/// </summary>
/// <param name="obj">The object to compare with.</param>
/// <returns>Whether or not the vector and the object are equal.</returns>
public override readonly bool Equals(object obj)
public override readonly bool Equals([NotNullWhen(true)] object? obj)
{
return obj is Vector3 other && Equals(other);
}
@ -1118,7 +1121,7 @@ namespace Godot
/// Converts this <see cref="Vector3"/> to a string with the given <paramref name="format"/>.
/// </summary>
/// <returns>A string representation of this vector.</returns>
public readonly string ToString(string format)
public readonly string ToString(string? format)
{
return $"({X.ToString(format)}, {Y.ToString(format)}, {Z.ToString(format)})";
}

View File

@ -1,6 +1,9 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
#nullable enable
namespace Godot
{
/// <summary>
@ -590,7 +593,7 @@ namespace Godot
/// </summary>
/// <param name="obj">The object to compare with.</param>
/// <returns>Whether or not the vector and the object are equal.</returns>
public override readonly bool Equals(object obj)
public override readonly bool Equals([NotNullWhen(true)] object? obj)
{
return obj is Vector3I other && Equals(other);
}
@ -627,7 +630,7 @@ namespace Godot
/// Converts this <see cref="Vector3I"/> to a string with the given <paramref name="format"/>.
/// </summary>
/// <returns>A string representation of this vector.</returns>
public readonly string ToString(string format)
public readonly string ToString(string? format)
{
return $"({X.ToString(format)}, {Y.ToString(format)}, {Z.ToString(format)})";
}

View File

@ -1,6 +1,9 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
#nullable enable
namespace Godot
{
/// <summary>
@ -838,7 +841,7 @@ namespace Godot
/// </summary>
/// <param name="obj">The object to compare with.</param>
/// <returns>Whether or not the vector and the object are equal.</returns>
public override readonly bool Equals(object obj)
public override readonly bool Equals([NotNullWhen(true)] object? obj)
{
return obj is Vector4 other && Equals(other);
}
@ -900,7 +903,7 @@ namespace Godot
/// Converts this <see cref="Vector4"/> to a string with the given <paramref name="format"/>.
/// </summary>
/// <returns>A string representation of this vector.</returns>
public readonly string ToString(string format)
public readonly string ToString(string? format)
{
return $"({X.ToString(format)}, {Y.ToString(format)}, {Z.ToString(format)}, {W.ToString(format)})";
}

View File

@ -1,6 +1,9 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
#nullable enable
namespace Godot
{
/// <summary>
@ -611,7 +614,7 @@ namespace Godot
/// </summary>
/// <param name="obj">The object to compare with.</param>
/// <returns>Whether or not the vector and the object are equal.</returns>
public override readonly bool Equals(object obj)
public override readonly bool Equals([NotNullWhen(true)] object? obj)
{
return obj is Vector4I other && Equals(other);
}
@ -648,7 +651,7 @@ namespace Godot
/// Converts this <see cref="Vector4I"/> to a string with the given <paramref name="format"/>.
/// </summary>
/// <returns>A string representation of this vector.</returns>
public readonly string ToString(string format)
public readonly string ToString(string? format)
{
return $"({X.ToString(format)}, {Y.ToString(format)}, {Z.ToString(format)}), {W.ToString(format)})";
}