Added dedicated exception for missing method source
このコミットが含まれているのは:
1 親
f4bd3f87b9
コミット
d1e91d71ab
5ファイル変更
+75
-7
検索条件に一致するファイルはありません
@@ -11,6 +11,9 @@ namespace ComputeSharp.Exceptions
|
||||
/// Creates a new <see cref="InvalidExecutionContextException"/> instance
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the caller API</param>
|
||||
internal InvalidExecutionContextException(string name) : base($"The API {name} can only be used from within an HLSL shader") { }
|
||||
internal InvalidExecutionContextException(string name)
|
||||
: base($"The API {name} can only be used from within an HLSL shader.")
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Text;
|
||||
using ComputeSharp.Core.Extensions;
|
||||
|
||||
#pragma warning disable CS0618
|
||||
|
||||
namespace ComputeSharp.Exceptions
|
||||
{
|
||||
/// <summary>
|
||||
/// A custom <see cref="InvalidOperationException"/> that indicates when an HLSL-only API is called from C#
|
||||
/// </summary>
|
||||
public sealed class MissingMethodSourceException : InvalidOperationException
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="MissingMethodSourceException"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="message">The exception message to display.</param>
|
||||
private MissingMethodSourceException(string message)
|
||||
: base(message)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="MissingMethodSourceException"/> instance from the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="method">The target <see cref="Delegate"/> that couldn't be processed.</param>
|
||||
/// <returns>A new <see cref="MissingMethodSourceException"/> instance with a formatted error message.</returns>
|
||||
[Pure]
|
||||
private static MissingMethodSourceException Create(Delegate method)
|
||||
{
|
||||
StringBuilder builder = new(512);
|
||||
|
||||
builder.AppendLine("The processed source for a method captured as a delegate in a shader was not found.");
|
||||
builder.AppendLine($"The delegate was of type {method.GetType()} and it was wrapping the method {method.Method.GetFullName()}.");
|
||||
builder.Append($"Make sure that the target method is annotated with [{nameof(ShaderMethodAttribute)}].");
|
||||
builder.ToString();
|
||||
|
||||
return new(builder.ToString());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="MissingMethodSourceException"/> for a given delegate.
|
||||
/// </summary>
|
||||
/// <param name="method">The target <see cref="Delegate"/> that couldn't be processed.</param>
|
||||
/// <returns>This method always throws and never actually returns anything.</returns>
|
||||
internal static ShaderMethodSourceAttribute Throw(Delegate method)
|
||||
{
|
||||
throw Create(method);
|
||||
}
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする