Skip to main content
Version: 0.3.x (0.3.0)

Class ValueObjectBadRequest

Namespace: AdCodicem.ValueObjects.Grpc
Assembly: AdCodicem.ValueObjects.Grpc.dll

Creates the value objects a contract-first request maps its fields to, records each value they refuse as a google.rpc.BadRequest field violation, and answers them all at once as INVALID_ARGUMENT.

public sealed class ValueObjectBadRequest

Inheritance​

object ← ValueObjectBadRequest

Inherited Members​

object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.ReferenceEquals(object?, object?), object.ToString()

Remarks​

One per request: var sku = request.Create<Sku, string>(message.Sku, "sku") for each field, then , which throws the Google.Rpc.Status.ToRpcException() builds when anything was refused. Each violation's field is the path given, an element of a repeated field skus[1]; its reason the code mapped by , left empty for a code that maps to no gRPC reason; its description the rule's message, in English, never the value.

A value refused leaves the default instance where it was asked for, which no rule checked: read every field before calling , and use nothing created before it returns.

Properties​

Violations​

Gets the field violations recorded so far, in the order the fields were read.

public IReadOnlyList<BadRequest.Types.FieldViolation> Violations { get; }

Property Value​

IReadOnlyList<BadRequest.Types.FieldViolation>

Methods​

Create<TSelf, TValue>(TValue, string)​

Creates a value object from a field, or records its refusal under the field's path.

public TSelf Create<TSelf, TValue>(TValue value, string field) where TSelf : struct, IValueObject<TSelf, TValue>

Parameters​

value TValue

The field's value.

field string

The field's path in the request, sku or order.lines[2].sku.

Returns​

TSelf

The value object, or the default instance when the value is refused.

Type Parameters​

TSelf

Value object type.

TValue

Underlying value type, the field's.

Exceptions​

ArgumentException

field is null, empty or white space.

CreateAll<TSelf, TValue>(IEnumerable<TValue>, string)​

Creates a value object from each element of a repeated field, recording each refusal under the element's path.

public IReadOnlyList<TSelf> CreateAll<TSelf, TValue>(IEnumerable<TValue> values, string field) where TSelf : struct, IValueObject<TSelf, TValue>

Parameters​

values IEnumerable<TValue>

The field's elements.

field string

The field's path in the request; each element's is field[index].

Returns​

IReadOnlyList<TSelf>

The value objects, a default instance in place of each one refused.

Type Parameters​

TSelf

Value object type.

TValue

Underlying value type, the field's elements'.

Exceptions​

ArgumentNullException

values is null.

ArgumentException

field is null, empty or white space.

ThrowIfAny(string)​

Throws, when any value was refused, an answering them all: INVALID_ARGUMENT, whose trailers carry a google.rpc.Status holding the google.rpc.BadRequest.

public void ThrowIfAny(string message = "The request holds values its value objects refuse.")

Parameters​

message string

The status message, in English, for the developer who reads it.

Exceptions​

RpcException

A value was refused.