fix: allow actually specifying fallibility
This commit is contained in:
parent
e479bc56f9
commit
42ee8b6ca3
22
Siggingway/Fallibility.cs
Executable file
22
Siggingway/Fallibility.cs
Executable 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,
|
||||||
|
}
|
|
@ -35,7 +35,14 @@ public static class Siggingway {
|
||||||
wasWrapped = true;
|
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) {
|
void Invalid(string message, bool prepend = true) {
|
||||||
var errorMsg = prepend
|
var errorMsg = prepend
|
||||||
|
|
|
@ -53,7 +53,7 @@ public sealed class SignatureAttribute : Attribute {
|
||||||
/// exceptions instead. If fallibility is not specified, it is inferred
|
/// exceptions instead. If fallibility is not specified, it is inferred
|
||||||
/// based on if the field/property is nullable.
|
/// based on if the field/property is nullable.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool? Fallible;
|
public Fallibility Fallibility = Fallibility.Auto;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create a <see cref="SignatureAttribute"/> with the given signature.
|
/// Create a <see cref="SignatureAttribute"/> with the given signature.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user