fix: allow actually specifying fallibility

This commit is contained in:
Anna 2022-01-13 00:53:41 -05:00
parent e479bc56f9
commit 42ee8b6ca3
3 changed files with 31 additions and 2 deletions

22
Siggingway/Fallibility.cs Executable file
View File

@ -0,0 +1,22 @@
namespace Siggingway;
/// <summary>
/// The fallibility of a signature.
/// </summary>
public enum Fallibility {
/// <summary>
/// The fallibility of the signature is determined by the field/property's
/// nullability.
/// </summary>
Auto,
/// <summary>
/// The signature is fallible.
/// </summary>
Fallible,
/// <summary>
/// The signature is infallible.
/// </summary>
Infallible,
}

View File

@ -35,7 +35,14 @@ public static class Siggingway {
wasWrapped = true;
}
var fallible = sig!.Fallible ?? info.IsNullable || wasWrapped;
var fallibility = sig!.Fallibility;
if (fallibility == Fallibility.Auto) {
fallibility = info.IsNullable || wasWrapped
? Fallibility.Fallible
: Fallibility.Infallible;
}
var fallible = fallibility == Fallibility.Fallible;
void Invalid(string message, bool prepend = true) {
var errorMsg = prepend

View File

@ -53,7 +53,7 @@ public sealed class SignatureAttribute : Attribute {
/// exceptions instead. If fallibility is not specified, it is inferred
/// based on if the field/property is nullable.
/// </summary>
public bool? Fallible;
public Fallibility Fallibility = Fallibility.Auto;
/// <summary>
/// Create a <see cref="SignatureAttribute"/> with the given signature.