Table of Contents

Class RequiredBool<TSelf>

Namespace
Trellis
Assembly
Trellis.Primitives.dll

Base class for creating strongly-typed boolean value objects that distinguish between false (an explicit value) and null/missing (no value provided).

public abstract class RequiredBool<TSelf> : ScalarValueObject<TSelf, bool>, IComparable<ValueObject>, IComparable, IEquatable<ValueObject>, IConvertible, IFormattable where TSelf : RequiredBool<TSelf>, IScalarValue<TSelf, bool>

Type Parameters

TSelf
Inheritance
RequiredBool<TSelf>
Implements
Inherited Members
Extension Methods

Examples

Creating a strongly-typed boolean value object:

public partial class GiftWrap : RequiredBool<GiftWrap> { }

var result = GiftWrap.TryCreate(true);
var noWrap = GiftWrap.TryCreate(false); // Success — false is a valid value!
var missing = GiftWrap.TryCreate((bool?)null); // Failure — null is rejected

Remarks

This class extends ScalarValueObject<TSelf, T> to provide a specialized base for boolean-based value objects. When used with the partial keyword, the PrimitiveValueObjectGenerator source generator automatically creates:

  • IScalarValue<TSelf, bool> implementation for ASP.NET Core automatic validation
  • TryCreate(bool) - Factory method for booleans (required by IScalarValue)
  • TryCreate(bool?, string?) - Factory method with null validation and custom field name
  • TryCreate(string?, string?) - Factory method for parsing strings with validation
  • IParsable<T> implementation (Parse, TryParse)
  • JSON serialization support via ParsableJsonConverter<T>
  • Explicit cast operator from bool
  • OpenTelemetry activity tracing

Common use cases:

  • Feature flags (IsEnabled, IsActive) where false is meaningful
  • Consent tracking (HasConsented, AcceptedTerms)
  • Configuration options (GiftWrap, ExpressShipping)
  • Any domain concept where null vs false distinction matters

Constructors

RequiredBool(bool)

Initializes a new instance of the RequiredBool<TSelf> class with the specified boolean value.

protected RequiredBool(bool value)

Parameters

value bool

The boolean value.

See Also

ScalarValueObject<TSelf, T>
RequiredInt<TSelf>