1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-25 15:37:42 +00:00

Merge pull request #64900 from raulsntos/dotnet/fix-exceptions

Fix various C# exceptions
This commit is contained in:
Ignacio Roldán Etcheverry
2022-08-29 01:22:39 +02:00
committed by GitHub
36 changed files with 122 additions and 94 deletions

View File

@@ -16,7 +16,7 @@ namespace Godot.SourceGenerators
INamedTypeSymbol GetTypeByMetadataNameOrThrow(string fullyQualifiedMetadataName) INamedTypeSymbol GetTypeByMetadataNameOrThrow(string fullyQualifiedMetadataName)
{ {
return compilation.GetTypeByMetadataName(fullyQualifiedMetadataName) ?? return compilation.GetTypeByMetadataName(fullyQualifiedMetadataName) ??
throw new InvalidOperationException("Type not found: " + fullyQualifiedMetadataName); throw new InvalidOperationException($"Type not found: '{fullyQualifiedMetadataName}'.");
} }
GodotObjectType = GetTypeByMetadataNameOrThrow("Godot.Object"); GodotObjectType = GetTypeByMetadataNameOrThrow("Godot.Object");

View File

@@ -21,14 +21,14 @@ namespace GodotTools.IdeMessaging.Utils
public void OnCompleted(Action continuation) public void OnCompleted(Action continuation)
{ {
if (this.continuation != null) if (this.continuation != null)
throw new InvalidOperationException("This awaiter has already been listened"); throw new InvalidOperationException("This awaiter already has a continuation.");
this.continuation = continuation; this.continuation = continuation;
} }
public void SetResult(T result) public void SetResult(T result)
{ {
if (IsCompleted) if (IsCompleted)
throw new InvalidOperationException("This awaiter is already completed"); throw new InvalidOperationException("This awaiter is already completed.");
IsCompleted = true; IsCompleted = true;
this.result = result; this.result = result;
@@ -39,7 +39,7 @@ namespace GodotTools.IdeMessaging.Utils
public void SetException(Exception exception) public void SetException(Exception exception)
{ {
if (IsCompleted) if (IsCompleted)
throw new InvalidOperationException("This awaiter is already completed"); throw new InvalidOperationException("This awaiter is already completed.");
IsCompleted = true; IsCompleted = true;
this.exception = exception; this.exception = exception;

View File

@@ -15,7 +15,7 @@ namespace GodotTools.ProjectEditor
public static ProjectRootElement GenGameProject(string name) public static ProjectRootElement GenGameProject(string name)
{ {
if (name.Length == 0) if (name.Length == 0)
throw new ArgumentException("Project name is empty", nameof(name)); throw new ArgumentException("Project name is empty.", nameof(name));
var root = ProjectRootElement.Create(NewProjectFileOptions.None); var root = ProjectRootElement.Create(NewProjectFileOptions.None);
@@ -37,7 +37,7 @@ namespace GodotTools.ProjectEditor
public static string GenAndSaveGameProject(string dir, string name) public static string GenAndSaveGameProject(string dir, string name)
{ {
if (name.Length == 0) if (name.Length == 0)
throw new ArgumentException("Project name is empty", nameof(name)); throw new ArgumentException("Project name is empty.", nameof(name));
string path = Path.Combine(dir, name + ".csproj"); string path = Path.Combine(dir, name + ".csproj");

View File

@@ -62,7 +62,7 @@ namespace GodotTools.Build
private static bool Build(BuildInfo buildInfo) private static bool Build(BuildInfo buildInfo)
{ {
if (_buildInProgress != null) if (_buildInProgress != null)
throw new InvalidOperationException("A build is already in progress"); throw new InvalidOperationException("A build is already in progress.");
_buildInProgress = buildInfo; _buildInProgress = buildInfo;
@@ -111,7 +111,7 @@ namespace GodotTools.Build
public static async Task<bool> BuildAsync(BuildInfo buildInfo) public static async Task<bool> BuildAsync(BuildInfo buildInfo)
{ {
if (_buildInProgress != null) if (_buildInProgress != null)
throw new InvalidOperationException("A build is already in progress"); throw new InvalidOperationException("A build is already in progress.");
_buildInProgress = buildInfo; _buildInProgress = buildInfo;
@@ -157,7 +157,7 @@ namespace GodotTools.Build
private static bool Publish(BuildInfo buildInfo) private static bool Publish(BuildInfo buildInfo)
{ {
if (_buildInProgress != null) if (_buildInProgress != null)
throw new InvalidOperationException("A build is already in progress"); throw new InvalidOperationException("A build is already in progress.");
_buildInProgress = buildInfo; _buildInProgress = buildInfo;

View File

@@ -120,13 +120,13 @@ namespace GodotTools.Build
private void IssueActivated(int idx) private void IssueActivated(int idx)
{ {
if (idx < 0 || idx >= _issuesList.ItemCount) if (idx < 0 || idx >= _issuesList.ItemCount)
throw new IndexOutOfRangeException("Item list index out of range"); throw new ArgumentOutOfRangeException(nameof(idx), "Item list index out of range.");
// Get correct issue idx from issue list // Get correct issue idx from issue list
int issueIndex = (int)_issuesList.GetItemMetadata(idx); int issueIndex = (int)_issuesList.GetItemMetadata(idx);
if (issueIndex < 0 || issueIndex >= _issues.Count) if (issueIndex < 0 || issueIndex >= _issues.Count)
throw new IndexOutOfRangeException("Issue index out of range"); throw new InvalidOperationException("Issue index out of range.");
BuildIssue issue = _issues[issueIndex]; BuildIssue issue = _issues[issueIndex];
@@ -293,7 +293,7 @@ namespace GodotTools.Build
public void RestartBuild() public void RestartBuild()
{ {
if (!HasBuildExited) if (!HasBuildExited)
throw new InvalidOperationException("Build already started"); throw new InvalidOperationException("Build already started.");
BuildManager.RestartBuild(this); BuildManager.RestartBuild(this);
} }
@@ -301,7 +301,7 @@ namespace GodotTools.Build
public void StopBuild() public void StopBuild()
{ {
if (!HasBuildExited) if (!HasBuildExited)
throw new InvalidOperationException("Build is not in progress"); throw new InvalidOperationException("Build is not in progress.");
BuildManager.StopBuild(this); BuildManager.StopBuild(this);
} }

View File

@@ -49,7 +49,7 @@ namespace GodotTools.Build
{ {
// Check that the root node is the expected one // Check that the root node is the expected one
if (rootNode.Name != nuGetConfigRootName) if (rootNode.Name != nuGetConfigRootName)
throw new Exception("Invalid root Xml node for NuGet.Config. " + throw new FormatException("Invalid root Xml node for NuGet.Config. " +
$"Expected '{nuGetConfigRootName}' got '{rootNode.Name}'."); $"Expected '{nuGetConfigRootName}' got '{rootNode.Name}'.");
} }

View File

@@ -212,7 +212,7 @@ namespace GodotTools.Export
int clangExitCode = OS.ExecuteCommand(XcodeHelper.FindXcodeTool("clang"), clangArgs); int clangExitCode = OS.ExecuteCommand(XcodeHelper.FindXcodeTool("clang"), clangArgs);
if (clangExitCode != 0) if (clangExitCode != 0)
throw new Exception($"Command 'clang' exited with code: {clangExitCode}"); throw new InvalidOperationException($"Command 'clang' exited with code: {clangExitCode}.");
objFilePathsForiOSArch[arch].Add(objFilePath); objFilePathsForiOSArch[arch].Add(objFilePath);
} }
@@ -318,7 +318,7 @@ MONO_AOT_MODE_LAST = 1000,
int arExitCode = OS.ExecuteCommand(XcodeHelper.FindXcodeTool("ar"), arArgs); int arExitCode = OS.ExecuteCommand(XcodeHelper.FindXcodeTool("ar"), arArgs);
if (arExitCode != 0) if (arExitCode != 0)
throw new Exception($"Command 'ar' exited with code: {arExitCode}"); throw new InvalidOperationException($"Command 'ar' exited with code: {arExitCode}.");
arFilePathsForAllArchs.Add(arOutputFilePath); arFilePathsForAllArchs.Add(arOutputFilePath);
} }
@@ -336,7 +336,7 @@ MONO_AOT_MODE_LAST = 1000,
int lipoExitCode = OS.ExecuteCommand(XcodeHelper.FindXcodeTool("lipo"), lipoArgs); int lipoExitCode = OS.ExecuteCommand(XcodeHelper.FindXcodeTool("lipo"), lipoArgs);
if (lipoExitCode != 0) if (lipoExitCode != 0)
throw new Exception($"Command 'lipo' exited with code: {lipoExitCode}"); throw new InvalidOperationException($"Command 'lipo' exited with code: {lipoExitCode}.");
// TODO: Add the AOT lib and interpreter libs as device only to suppress warnings when targeting the simulator // TODO: Add the AOT lib and interpreter libs as device only to suppress warnings when targeting the simulator
@@ -436,7 +436,7 @@ MONO_AOT_MODE_LAST = 1000,
} }
else if (!Directory.Exists(androidToolchain)) else if (!Directory.Exists(androidToolchain))
{ {
throw new FileNotFoundException("Android toolchain not found: " + androidToolchain); throw new FileNotFoundException($"Android toolchain not found: '{androidToolchain}'.");
} }
var androidToolPrefixes = new Dictionary<string, string> var androidToolPrefixes = new Dictionary<string, string>
@@ -533,12 +533,12 @@ MONO_AOT_MODE_LAST = 1000,
Console.WriteLine($"Running: \"{process.StartInfo.FileName}\" {process.StartInfo.Arguments}"); Console.WriteLine($"Running: \"{process.StartInfo.FileName}\" {process.StartInfo.Arguments}");
if (!process.Start()) if (!process.Start())
throw new Exception("Failed to start process for Mono AOT compiler"); throw new InvalidOperationException("Failed to start process for Mono AOT compiler.");
process.WaitForExit(); process.WaitForExit();
if (process.ExitCode != 0) if (process.ExitCode != 0)
throw new Exception($"Mono AOT compiler exited with code: {process.ExitCode}"); throw new InvalidOperationException($"Mono AOT compiler exited with code: {process.ExitCode}.");
} }
} }

View File

@@ -98,16 +98,16 @@ namespace GodotTools.Export
return; return;
if (!DeterminePlatformFromFeatures(features, out string platform)) if (!DeterminePlatformFromFeatures(features, out string platform))
throw new NotSupportedException("Target platform not supported"); throw new NotSupportedException("Target platform not supported.");
if (!new[] { OS.Platforms.Windows, OS.Platforms.LinuxBSD, OS.Platforms.MacOS } if (!new[] { OS.Platforms.Windows, OS.Platforms.LinuxBSD, OS.Platforms.MacOS }
.Contains(platform)) .Contains(platform))
{ {
throw new NotImplementedException("Target platform not yet implemented"); throw new NotImplementedException("Target platform not yet implemented.");
} }
string outputDir = new FileInfo(path).Directory?.FullName ?? string outputDir = new FileInfo(path).Directory?.FullName ??
throw new FileNotFoundException("Output base directory not found"); throw new FileNotFoundException("Output base directory not found.");
string buildConfig = isDebug ? "ExportDebug" : "ExportRelease"; string buildConfig = isDebug ? "ExportDebug" : "ExportRelease";
@@ -131,7 +131,7 @@ namespace GodotTools.Export
if (!BuildManager.PublishProjectBlocking(buildConfig, platform, if (!BuildManager.PublishProjectBlocking(buildConfig, platform,
runtimeIdentifier, publishOutputTempDir)) runtimeIdentifier, publishOutputTempDir))
{ {
throw new Exception("Failed to build project"); throw new InvalidOperationException("Failed to build project.");
} }
string soExt = ridOS switch string soExt = ridOS switch

View File

@@ -16,7 +16,7 @@ namespace GodotTools.Export
_XcodePath = FindXcode(); _XcodePath = FindXcode();
if (_XcodePath == null) if (_XcodePath == null)
throw new Exception("Could not find Xcode"); throw new FileNotFoundException("Could not find Xcode.");
} }
return _XcodePath; return _XcodePath;

View File

@@ -342,7 +342,7 @@ namespace GodotTools
DotNetSolution.MigrateFromOldConfigNames(GodotSharpDirs.ProjectSlnPath); DotNetSolution.MigrateFromOldConfigNames(GodotSharpDirs.ProjectSlnPath);
var msbuildProject = ProjectUtils.Open(GodotSharpDirs.ProjectCsProjPath) var msbuildProject = ProjectUtils.Open(GodotSharpDirs.ProjectCsProjPath)
?? throw new Exception("Cannot open C# project"); ?? throw new InvalidOperationException("Cannot open C# project.");
// NOTE: The order in which changes are made to the project is important // NOTE: The order in which changes are made to the project is important

View File

@@ -153,7 +153,7 @@ namespace GodotTools.Ides
} }
default: default:
throw new ArgumentOutOfRangeException(); throw new ArgumentOutOfRangeException(nameof(editorId));
} }
} }

View File

@@ -42,7 +42,7 @@ namespace GodotTools.Ides.Rider
{ {
return CollectAllRiderPathsLinux(); return CollectAllRiderPathsLinux();
} }
throw new Exception("Unexpected OS."); throw new InvalidOperationException("Unexpected OS.");
} }
catch (Exception e) catch (Exception e)
{ {
@@ -216,7 +216,7 @@ namespace GodotTools.Ides.Rider
return "../../build.txt"; return "../../build.txt";
if (OS.IsMacOS) if (OS.IsMacOS)
return "Contents/Resources/build.txt"; return "Contents/Resources/build.txt";
throw new Exception("Unknown OS."); throw new InvalidOperationException("Unknown OS.");
} }
[SupportedOSPlatform("windows")] [SupportedOSPlatform("windows")]

View File

@@ -74,11 +74,11 @@ namespace GodotTools.Internals
internal static unsafe void Initialize(IntPtr unmanagedCallbacks, int unmanagedCallbacksSize) internal static unsafe void Initialize(IntPtr unmanagedCallbacks, int unmanagedCallbacksSize)
{ {
if (initialized) if (initialized)
throw new InvalidOperationException("Already initialized"); throw new InvalidOperationException("Already initialized.");
initialized = true; initialized = true;
if (unmanagedCallbacksSize != sizeof(InternalUnmanagedCallbacks)) if (unmanagedCallbacksSize != sizeof(InternalUnmanagedCallbacks))
throw new ArgumentException("Unmanaged callbacks size mismatch"); throw new ArgumentException("Unmanaged callbacks size mismatch.", nameof(unmanagedCallbacksSize));
_unmanagedCallbacks = Unsafe.AsRef<InternalUnmanagedCallbacks>((void*)unmanagedCallbacks); _unmanagedCallbacks = Unsafe.AsRef<InternalUnmanagedCallbacks>((void*)unmanagedCallbacks);
} }

View File

@@ -257,7 +257,7 @@ namespace GodotTools.Utils
using Process process = Process.Start(startInfo); using Process process = Process.Start(startInfo);
if (process == null) if (process == null)
throw new Exception("No process was started"); throw new InvalidOperationException("No process was started.");
process.BeginOutputReadLine(); process.BeginOutputReadLine();
process.BeginErrorReadLine(); process.BeginErrorReadLine();

View File

@@ -153,7 +153,7 @@ namespace GodotPlugins
string assemblyPath = new(nAssemblyPath); string assemblyPath = new(nAssemblyPath);
if (_editorApiAssembly == null) if (_editorApiAssembly == null)
throw new InvalidOperationException("The Godot editor API assembly is not loaded"); throw new InvalidOperationException("The Godot editor API assembly is not loaded.");
var (assembly, _) = LoadPlugin(assemblyPath); var (assembly, _) = LoadPlugin(assemblyPath);

View File

@@ -145,6 +145,9 @@ namespace Godot
/// Gets the position of one of the 8 endpoints of the <see cref="AABB"/>. /// Gets the position of one of the 8 endpoints of the <see cref="AABB"/>.
/// </summary> /// </summary>
/// <param name="idx">Which endpoint to get.</param> /// <param name="idx">Which endpoint to get.</param>
/// <exception cref="ArgumentOutOfRangeException">
/// <paramref name="idx"/> is less than 0 or greater than 7.
/// </exception>
/// <returns>An endpoint of the <see cref="AABB"/>.</returns> /// <returns>An endpoint of the <see cref="AABB"/>.</returns>
public Vector3 GetEndpoint(int idx) public Vector3 GetEndpoint(int idx)
{ {

View File

@@ -510,7 +510,7 @@ namespace Godot.Collections
if (_convertToVariantCallback == null || _convertToManagedCallback == null) if (_convertToVariantCallback == null || _convertToManagedCallback == null)
{ {
throw new InvalidOperationException( throw new InvalidOperationException(
$"The array element type is not supported for conversion to Variant: '{typeof(T).FullName}'"); $"The array element type is not supported for conversion to Variant: '{typeof(T).FullName}'.");
} }
} }

View File

@@ -148,6 +148,9 @@ namespace Godot
/// Access whole columns in the form of <see cref="Vector3"/>. /// Access whole columns in the form of <see cref="Vector3"/>.
/// </summary> /// </summary>
/// <param name="column">Which column vector.</param> /// <param name="column">Which column vector.</param>
/// <exception cref="ArgumentOutOfRangeException">
/// <paramref name="column"/> is not 0, 1, 2 or 3.
/// </exception>
/// <value>The basis column.</value> /// <value>The basis column.</value>
public Vector3 this[int column] public Vector3 this[int column]
{ {
@@ -366,8 +369,8 @@ namespace Godot
/// but are more efficient for some internal calculations. /// but are more efficient for some internal calculations.
/// </summary> /// </summary>
/// <param name="index">Which row.</param> /// <param name="index">Which row.</param>
/// <exception cref="IndexOutOfRangeException"> /// <exception cref="ArgumentOutOfRangeException">
/// Thrown when the <paramref name="index"/> is not 0, 1 or 2. /// <paramref name="index"/> is not 0, 1 or 2.
/// </exception> /// </exception>
/// <returns>One of <c>Row0</c>, <c>Row1</c>, or <c>Row2</c>.</returns> /// <returns>One of <c>Row0</c>, <c>Row1</c>, or <c>Row2</c>.</returns>
public Vector3 GetRow(int index) public Vector3 GetRow(int index)
@@ -391,8 +394,8 @@ namespace Godot
/// </summary> /// </summary>
/// <param name="index">Which row.</param> /// <param name="index">Which row.</param>
/// <param name="value">The vector to set the row to.</param> /// <param name="value">The vector to set the row to.</param>
/// <exception cref="IndexOutOfRangeException"> /// <exception cref="ArgumentOutOfRangeException">
/// Thrown when the <paramref name="index"/> is not 0, 1 or 2. /// <paramref name="index"/> is not 0, 1 or 2.
/// </exception> /// </exception>
public void SetRow(int index, Vector3 value) public void SetRow(int index, Vector3 value)
{ {

View File

@@ -595,7 +595,7 @@ namespace Godot
/// </summary> /// </summary>
/// <param name="rgba">A string for the HTML hexadecimal representation of this color.</param> /// <param name="rgba">A string for the HTML hexadecimal representation of this color.</param>
/// <exception name="ArgumentOutOfRangeException"> /// <exception name="ArgumentOutOfRangeException">
/// Thrown when the given <paramref name="rgba"/> color code is invalid. /// <paramref name="rgba"/> color code is invalid.
/// </exception> /// </exception>
private static Color FromHTML(string rgba) private static Color FromHTML(string rgba)
{ {

View File

@@ -171,7 +171,7 @@ namespace Godot.Collections
var self = (godot_dictionary)NativeValue; var self = (godot_dictionary)NativeValue;
if (NativeFuncs.godotsharp_dictionary_contains_key(ref self, variantKey).ToBool()) if (NativeFuncs.godotsharp_dictionary_contains_key(ref self, variantKey).ToBool())
throw new ArgumentException("An element with the same key already exists", nameof(key)); throw new ArgumentException("An element with the same key already exists.", nameof(key));
godot_variant variantValue = (godot_variant)value.NativeVar; godot_variant variantValue = (godot_variant)value.NativeVar;
NativeFuncs.godotsharp_dictionary_add(ref self, variantKey, variantValue); NativeFuncs.godotsharp_dictionary_add(ref self, variantKey, variantValue);
@@ -381,13 +381,13 @@ namespace Godot.Collections
if (_convertKeyToVariantCallback == null || _convertKeyToManagedCallback == null) if (_convertKeyToVariantCallback == null || _convertKeyToManagedCallback == null)
{ {
throw new InvalidOperationException( throw new InvalidOperationException(
$"The dictionary key type is not supported for conversion to Variant: '{typeof(TKey).FullName}'"); $"The dictionary key type is not supported for conversion to Variant: '{typeof(TKey).FullName}'.");
} }
if (_convertValueToVariantCallback == null || _convertValueToManagedCallback == null) if (_convertValueToVariantCallback == null || _convertValueToManagedCallback == null)
{ {
throw new InvalidOperationException( throw new InvalidOperationException(
$"The dictionary value type is not supported for conversion to Variant: '{typeof(TValue).FullName}'"); $"The dictionary value type is not supported for conversion to Variant: '{typeof(TValue).FullName}'.");
} }
} }
@@ -556,7 +556,7 @@ namespace Godot.Collections
var self = (godot_dictionary)_underlyingDict.NativeValue; var self = (godot_dictionary)_underlyingDict.NativeValue;
if (NativeFuncs.godotsharp_dictionary_contains_key(ref self, variantKey).ToBool()) if (NativeFuncs.godotsharp_dictionary_contains_key(ref self, variantKey).ToBool())
throw new ArgumentException("An element with the same key already exists", nameof(key)); throw new ArgumentException("An element with the same key already exists.", nameof(key));
using var variantValue = _convertValueToVariantCallback(value); using var variantValue = _convertValueToVariantCallback(value);
NativeFuncs.godotsharp_dictionary_add(ref self, variantKey, variantValue); NativeFuncs.godotsharp_dictionary_add(ref self, variantKey, variantValue);

View File

@@ -83,13 +83,13 @@ namespace Godot
public static void UnregisterGodotObject(Object godotObject, WeakReference<Object> weakReferenceToSelf) public static void UnregisterGodotObject(Object godotObject, WeakReference<Object> weakReferenceToSelf)
{ {
if (!GodotObjectInstances.TryRemove(weakReferenceToSelf, out _)) if (!GodotObjectInstances.TryRemove(weakReferenceToSelf, out _))
throw new ArgumentException("Godot Object not registered", nameof(weakReferenceToSelf)); throw new ArgumentException("Godot Object not registered.", nameof(weakReferenceToSelf));
} }
public static void UnregisterDisposable(WeakReference<IDisposable> weakReference) public static void UnregisterDisposable(WeakReference<IDisposable> weakReference)
{ {
if (!OtherInstances.TryRemove(weakReference, out _)) if (!OtherInstances.TryRemove(weakReference, out _))
throw new ArgumentException("Disposable not registered", nameof(weakReference)); throw new ArgumentException("Disposable not registered.", nameof(weakReference));
} }
} }
} }

View File

@@ -36,7 +36,7 @@ namespace Godot
/// <seealso cref="GetNodeOrNull{T}(NodePath)"/> /// <seealso cref="GetNodeOrNull{T}(NodePath)"/>
/// <param name="path">The path to the node to fetch.</param> /// <param name="path">The path to the node to fetch.</param>
/// <exception cref="InvalidCastException"> /// <exception cref="InvalidCastException">
/// Thrown when the given the fetched node can't be casted to the given type <typeparamref name="T"/>. /// The fetched node can't be casted to the given type <typeparamref name="T"/>.
/// </exception> /// </exception>
/// <typeparam name="T">The type to cast to. Should be a descendant of <see cref="Node"/>.</typeparam> /// <typeparam name="T">The type to cast to. Should be a descendant of <see cref="Node"/>.</typeparam>
/// <returns> /// <returns>
@@ -100,7 +100,7 @@ namespace Godot
/// parameter in <see cref="AddChild(Node, bool, InternalMode)"/>). /// parameter in <see cref="AddChild(Node, bool, InternalMode)"/>).
/// </param> /// </param>
/// <exception cref="InvalidCastException"> /// <exception cref="InvalidCastException">
/// Thrown when the given the fetched node can't be casted to the given type <typeparamref name="T"/>. /// The fetched node can't be casted to the given type <typeparamref name="T"/>.
/// </exception> /// </exception>
/// <typeparam name="T">The type to cast to. Should be a descendant of <see cref="Node"/>.</typeparam> /// <typeparam name="T">The type to cast to. Should be a descendant of <see cref="Node"/>.</typeparam>
/// <returns> /// <returns>
@@ -142,7 +142,7 @@ namespace Godot
/// </summary> /// </summary>
/// <seealso cref="GetOwnerOrNull{T}"/> /// <seealso cref="GetOwnerOrNull{T}"/>
/// <exception cref="InvalidCastException"> /// <exception cref="InvalidCastException">
/// Thrown when the given the fetched node can't be casted to the given type <typeparamref name="T"/>. /// The fetched node can't be casted to the given type <typeparamref name="T"/>.
/// </exception> /// </exception>
/// <typeparam name="T">The type to cast to. Should be a descendant of <see cref="Node"/>.</typeparam> /// <typeparam name="T">The type to cast to. Should be a descendant of <see cref="Node"/>.</typeparam>
/// <returns> /// <returns>
@@ -176,7 +176,7 @@ namespace Godot
/// </summary> /// </summary>
/// <seealso cref="GetParentOrNull{T}"/> /// <seealso cref="GetParentOrNull{T}"/>
/// <exception cref="InvalidCastException"> /// <exception cref="InvalidCastException">
/// Thrown when the given the fetched node can't be casted to the given type <typeparamref name="T"/>. /// The fetched node can't be casted to the given type <typeparamref name="T"/>.
/// </exception> /// </exception>
/// <typeparam name="T">The type to cast to. Should be a descendant of <see cref="Node"/>.</typeparam> /// <typeparam name="T">The type to cast to. Should be a descendant of <see cref="Node"/>.</typeparam>
/// <returns> /// <returns>

View File

@@ -11,7 +11,7 @@ namespace Godot
/// </summary> /// </summary>
/// <seealso cref="InstantiateOrNull{T}(GenEditState)"/> /// <seealso cref="InstantiateOrNull{T}(GenEditState)"/>
/// <exception cref="InvalidCastException"> /// <exception cref="InvalidCastException">
/// Thrown when the given the instantiated node can't be casted to the given type <typeparamref name="T"/>. /// The instantiated node can't be casted to the given type <typeparamref name="T"/>.
/// </exception> /// </exception>
/// <typeparam name="T">The type to cast to. Should be a descendant of <see cref="Node"/>.</typeparam> /// <typeparam name="T">The type to cast to. Should be a descendant of <see cref="Node"/>.</typeparam>
/// <returns>The instantiated scene.</returns> /// <returns>The instantiated scene.</returns>

View File

@@ -19,7 +19,7 @@ namespace Godot
/// Returns an empty resource if no <see cref="ResourceFormatLoader"/> could handle the file. /// Returns an empty resource if no <see cref="ResourceFormatLoader"/> could handle the file.
/// </summary> /// </summary>
/// <exception cref="InvalidCastException"> /// <exception cref="InvalidCastException">
/// Thrown when the given the loaded resource can't be casted to the given type <typeparamref name="T"/>. /// The loaded resource can't be casted to the given type <typeparamref name="T"/>.
/// </exception> /// </exception>
/// <typeparam name="T">The type to cast to. Should be a descendant of <see cref="Resource"/>.</typeparam> /// <typeparam name="T">The type to cast to. Should be a descendant of <see cref="Resource"/>.</typeparam>
public static T Load<T>(string path, string typeHint = null, CacheMode cacheMode = CacheMode.Reuse) where T : class public static T Load<T>(string path, string typeHint = null, CacheMode cacheMode = CacheMode.Reuse) where T : class

View File

@@ -22,11 +22,11 @@ namespace Godot.NativeInterop
public static void Initialize(IntPtr unmanagedCallbacks, int unmanagedCallbacksSize) public static void Initialize(IntPtr unmanagedCallbacks, int unmanagedCallbacksSize)
{ {
if (initialized) if (initialized)
throw new InvalidOperationException("Already initialized"); throw new InvalidOperationException("Already initialized.");
initialized = true; initialized = true;
if (unmanagedCallbacksSize != sizeof(UnmanagedCallbacks)) if (unmanagedCallbacksSize != sizeof(UnmanagedCallbacks))
throw new ArgumentException("Unmanaged callbacks size mismatch"); throw new ArgumentException("Unmanaged callbacks size mismatch.", nameof(unmanagedCallbacksSize));
_unmanagedCallbacks = Unsafe.AsRef<UnmanagedCallbacks>((void*)unmanagedCallbacks); _unmanagedCallbacks = Unsafe.AsRef<UnmanagedCallbacks>((void*)unmanagedCallbacks);
} }

View File

@@ -1,4 +1,5 @@
using System; using System;
using System.Text;
#nullable enable #nullable enable
@@ -60,19 +61,22 @@ namespace Godot
{ {
get get
{ {
string s = base.Message; StringBuilder sb;
if (string.IsNullOrEmpty(base.Message))
if (string.IsNullOrEmpty(s))
{ {
s = Arg_NativeConstructorNotFoundException; sb = new(Arg_NativeConstructorNotFoundException);
}
else
{
sb = new(base.Message);
} }
if (!string.IsNullOrEmpty(_nativeClassName)) if (!string.IsNullOrEmpty(_nativeClassName))
{ {
s += " " + string.Format("(Class '{0}')", _nativeClassName); sb.Append($" (Method '{_nativeClassName}')");
} }
return s; return sb.ToString();
} }
} }
} }
@@ -115,19 +119,22 @@ namespace Godot
{ {
get get
{ {
string s = base.Message; StringBuilder sb;
if (string.IsNullOrEmpty(base.Message))
if (string.IsNullOrEmpty(s))
{ {
s = Arg_NativeMethodBindNotFoundException; sb = new(Arg_NativeMethodBindNotFoundException);
}
else
{
sb = new(base.Message);
} }
if (!string.IsNullOrEmpty(_nativeMethodName)) if (!string.IsNullOrEmpty(_nativeMethodName))
{ {
s += " " + string.Format("(Method '{0}')", _nativeMethodName); sb.Append($" (Method '{_nativeMethodName}')");
} }
return s; return sb.ToString();
} }
} }
} }

View File

@@ -649,6 +649,9 @@ namespace Godot
/// Access whole columns in the form of <see cref="Vector4"/>. /// Access whole columns in the form of <see cref="Vector4"/>.
/// </summary> /// </summary>
/// <param name="column">Which column vector.</param> /// <param name="column">Which column vector.</param>
/// <exception cref="ArgumentOutOfRangeException">
/// <paramref name="column"/> is not 0, 1, 2 or 3.
/// </exception>
public Vector4 this[int column] public Vector4 this[int column]
{ {
get get
@@ -664,7 +667,7 @@ namespace Godot
case 3: case 3:
return w; return w;
default: default:
throw new IndexOutOfRangeException(); throw new ArgumentOutOfRangeException(nameof(column));
} }
} }
set set
@@ -684,7 +687,7 @@ namespace Godot
w = value; w = value;
return; return;
default: default:
throw new IndexOutOfRangeException(); throw new ArgumentOutOfRangeException(nameof(column));
} }
} }
} }
@@ -694,6 +697,9 @@ namespace Godot
/// </summary> /// </summary>
/// <param name="column">Which column vector.</param> /// <param name="column">Which column vector.</param>
/// <param name="row">Which row of the column.</param> /// <param name="row">Which row of the column.</param>
/// <exception cref="ArgumentOutOfRangeException">
/// <paramref name="column"/> or <paramref name="row"/> are not 0, 1, 2 or 3.
/// </exception>
public real_t this[int column, int row] public real_t this[int column, int row]
{ {
get get
@@ -709,7 +715,7 @@ namespace Godot
case 3: case 3:
return w[row]; return w[row];
default: default:
throw new IndexOutOfRangeException(); throw new ArgumentOutOfRangeException(nameof(column));
} }
} }
set set
@@ -729,7 +735,7 @@ namespace Godot
w[row] = value; w[row] = value;
return; return;
default: default:
throw new IndexOutOfRangeException(); throw new ArgumentOutOfRangeException(nameof(column));
} }
} }
} }

View File

@@ -47,6 +47,9 @@ namespace Godot
/// <summary> /// <summary>
/// Access quaternion components using their index. /// Access quaternion components using their index.
/// </summary> /// </summary>
/// <exception cref="ArgumentOutOfRangeException">
/// <paramref name="index"/> is not 0, 1, 2 or 3.
/// </exception>
/// <value> /// <value>
/// <c>[0]</c> is equivalent to <see cref="x"/>, /// <c>[0]</c> is equivalent to <see cref="x"/>,
/// <c>[1]</c> is equivalent to <see cref="y"/>, /// <c>[1]</c> is equivalent to <see cref="y"/>,
@@ -314,7 +317,7 @@ namespace Godot
#if DEBUG #if DEBUG
if (!IsNormalized()) if (!IsNormalized())
{ {
throw new InvalidOperationException("Quaternion is not normalized"); throw new InvalidOperationException("Quaternion is not normalized.");
} }
#endif #endif
var basis = new Basis(this); var basis = new Basis(this);
@@ -330,7 +333,7 @@ namespace Godot
#if DEBUG #if DEBUG
if (!IsNormalized()) if (!IsNormalized())
{ {
throw new InvalidOperationException("Quaternion is not normalized"); throw new InvalidOperationException("Quaternion is not normalized.");
} }
#endif #endif
return new Quaternion(-x, -y, -z, w); return new Quaternion(-x, -y, -z, w);
@@ -374,11 +377,11 @@ namespace Godot
#if DEBUG #if DEBUG
if (!IsNormalized()) if (!IsNormalized())
{ {
throw new InvalidOperationException("Quaternion is not normalized"); throw new InvalidOperationException("Quaternion is not normalized.");
} }
if (!to.IsNormalized()) if (!to.IsNormalized())
{ {
throw new ArgumentException("Argument is not normalized", nameof(to)); throw new ArgumentException("Argument is not normalized.", nameof(to));
} }
#endif #endif
@@ -543,7 +546,7 @@ namespace Godot
#if DEBUG #if DEBUG
if (!axis.IsNormalized()) if (!axis.IsNormalized())
{ {
throw new ArgumentException("Argument is not normalized", nameof(axis)); throw new ArgumentException("Argument is not normalized.", nameof(axis));
} }
#endif #endif
@@ -599,7 +602,7 @@ namespace Godot
#if DEBUG #if DEBUG
if (!quaternion.IsNormalized()) if (!quaternion.IsNormalized())
{ {
throw new InvalidOperationException("Quaternion is not normalized"); throw new InvalidOperationException("Quaternion is not normalized.");
} }
#endif #endif
var u = new Vector3(quaternion.x, quaternion.y, quaternion.z); var u = new Vector3(quaternion.x, quaternion.y, quaternion.z);

View File

@@ -75,6 +75,9 @@ namespace Godot
/// The third column is the <see cref="origin"/> vector. /// The third column is the <see cref="origin"/> vector.
/// </summary> /// </summary>
/// <param name="column">Which column vector.</param> /// <param name="column">Which column vector.</param>
/// <exception cref="ArgumentOutOfRangeException">
/// <paramref name="column"/> is not 0, 1 or 2.
/// </exception>
public Vector2 this[int column] public Vector2 this[int column]
{ {
get get

View File

@@ -32,6 +32,9 @@ namespace Godot
/// The fourth column is the <see cref="origin"/> vector. /// The fourth column is the <see cref="origin"/> vector.
/// </summary> /// </summary>
/// <param name="column">Which column vector.</param> /// <param name="column">Which column vector.</param>
/// <exception cref="ArgumentOutOfRangeException">
/// <paramref name="column"/> is not 0, 1, 2 or 3.
/// </exception>
public Vector3 this[int column] public Vector3 this[int column]
{ {
get get

View File

@@ -39,8 +39,8 @@ namespace Godot
/// <summary> /// <summary>
/// Access vector components using their index. /// Access vector components using their index.
/// </summary> /// </summary>
/// <exception cref="IndexOutOfRangeException"> /// <exception cref="ArgumentOutOfRangeException">
/// Thrown when the given the <paramref name="index"/> is not 0 or 1. /// <paramref name="index"/> is not 0 or 1.
/// </exception> /// </exception>
/// <value> /// <value>
/// <c>[0]</c> is equivalent to <see cref="x"/>, /// <c>[0]</c> is equivalent to <see cref="x"/>,
@@ -502,7 +502,7 @@ namespace Godot
#if DEBUG #if DEBUG
if (!normal.IsNormalized()) if (!normal.IsNormalized())
{ {
throw new ArgumentException("Argument is not normalized", nameof(normal)); throw new ArgumentException("Argument is not normalized.", nameof(normal));
} }
#endif #endif
return (2 * Dot(normal) * normal) - this; return (2 * Dot(normal) * normal) - this;

View File

@@ -39,8 +39,8 @@ namespace Godot
/// <summary> /// <summary>
/// Access vector components using their index. /// Access vector components using their index.
/// </summary> /// </summary>
/// <exception cref="IndexOutOfRangeException"> /// <exception cref="ArgumentOutOfRangeException">
/// Thrown when the given the <paramref name="index"/> is not 0 or 1. /// <paramref name="index"/> is not 0 or 1.
/// </exception> /// </exception>
/// <value> /// <value>
/// <c>[0]</c> is equivalent to <see cref="x"/>, /// <c>[0]</c> is equivalent to <see cref="x"/>,

View File

@@ -48,8 +48,8 @@ namespace Godot
/// <summary> /// <summary>
/// Access vector components using their index. /// Access vector components using their index.
/// </summary> /// </summary>
/// <exception cref="IndexOutOfRangeException"> /// <exception cref="ArgumentOutOfRangeException">
/// Thrown when the given the <paramref name="index"/> is not 0, 1 or 2. /// <paramref name="index"/> is not 0, 1 or 2.
/// </exception> /// </exception>
/// <value> /// <value>
/// <c>[0]</c> is equivalent to <see cref="x"/>, /// <c>[0]</c> is equivalent to <see cref="x"/>,
@@ -521,7 +521,7 @@ namespace Godot
#if DEBUG #if DEBUG
if (!normal.IsNormalized()) if (!normal.IsNormalized())
{ {
throw new ArgumentException("Argument is not normalized", nameof(normal)); throw new ArgumentException("Argument is not normalized.", nameof(normal));
} }
#endif #endif
return (2.0f * Dot(normal) * normal) - this; return (2.0f * Dot(normal) * normal) - this;
@@ -539,7 +539,7 @@ namespace Godot
#if DEBUG #if DEBUG
if (!axis.IsNormalized()) if (!axis.IsNormalized())
{ {
throw new ArgumentException("Argument is not normalized", nameof(axis)); throw new ArgumentException("Argument is not normalized.", nameof(axis));
} }
#endif #endif
return new Basis(axis, angle) * this; return new Basis(axis, angle) * this;

View File

@@ -48,8 +48,8 @@ namespace Godot
/// <summary> /// <summary>
/// Access vector components using their <paramref name="index"/>. /// Access vector components using their <paramref name="index"/>.
/// </summary> /// </summary>
/// <exception cref="IndexOutOfRangeException"> /// <exception cref="ArgumentOutOfRangeException">
/// Thrown when the given the <paramref name="index"/> is not 0, 1 or 2. /// <paramref name="index"/> is not 0, 1 or 2.
/// </exception> /// </exception>
/// <value> /// <value>
/// <c>[0]</c> is equivalent to <see cref="x"/>, /// <c>[0]</c> is equivalent to <see cref="x"/>,

View File

@@ -57,8 +57,8 @@ namespace Godot
/// <summary> /// <summary>
/// Access vector components using their index. /// Access vector components using their index.
/// </summary> /// </summary>
/// <exception cref="IndexOutOfRangeException"> /// <exception cref="ArgumentOutOfRangeException">
/// Thrown when the given the <paramref name="index"/> is not 0, 1, 2 or 3. /// <paramref name="index"/> is not 0, 1, 2 or 3.
/// </exception> /// </exception>
/// <value> /// <value>
/// <c>[0]</c> is equivalent to <see cref="x"/>, /// <c>[0]</c> is equivalent to <see cref="x"/>,
@@ -81,7 +81,7 @@ namespace Godot
case 3: case 3:
return w; return w;
default: default:
throw new IndexOutOfRangeException(); throw new ArgumentOutOfRangeException(nameof(index));
} }
} }
set set
@@ -101,7 +101,7 @@ namespace Godot
w = value; w = value;
return; return;
default: default:
throw new IndexOutOfRangeException(); throw new ArgumentOutOfRangeException(nameof(index));
} }
} }
} }

View File

@@ -57,8 +57,8 @@ namespace Godot
/// <summary> /// <summary>
/// Access vector components using their <paramref name="index"/>. /// Access vector components using their <paramref name="index"/>.
/// </summary> /// </summary>
/// <exception cref="IndexOutOfRangeException"> /// <exception cref="ArgumentOutOfRangeException">
/// Thrown when the given the <paramref name="index"/> is not 0, 1, 2 or 3. /// <paramref name="index"/> is not 0, 1, 2 or 3.
/// </exception> /// </exception>
/// <value> /// <value>
/// <c>[0]</c> is equivalent to <see cref="x"/>, /// <c>[0]</c> is equivalent to <see cref="x"/>,
@@ -81,7 +81,7 @@ namespace Godot
case 3: case 3:
return w; return w;
default: default:
throw new IndexOutOfRangeException(); throw new ArgumentOutOfRangeException(nameof(index));
} }
} }
set set
@@ -101,7 +101,7 @@ namespace Godot
w = value; w = value;
return; return;
default: default:
throw new IndexOutOfRangeException(); throw new ArgumentOutOfRangeException(nameof(index));
} }
} }
} }