Table of Contents

Struct PolicyResult

Namespace
Excalibur.A3.Authorization
Assembly
Excalibur.A3.Core.dll

Represents the result of a policy evaluation.

public readonly struct PolicyResult : IEquatable<PolicyResult>
Implements
Inherited Members

Remarks

A value type, and the reason is measured. This is returned by every HasGrant call, and an authorization check runs on the dispatch path for every authorized message. As a reference type it cost one 24-byte heap allocation per check — for three booleans that the bool-returning overloads discard immediately.

The runtime sometimes removed that allocation, which is worse than it sounds. Because the result never escapes HasGrant, escape analysis can stack-allocate it — but only once the method reaches tier-1. Measured: the same authorization check allocated 24 bytes per call early in a process and zero later, with nothing in the code changing between the two. An allocation that disappears when the optimiser gets around to it is not a guarantee a consumer can rely on, and it cannot be asserted by a test without the test becoming a measurement of the JIT. As a struct there is no allocation to eliminate, so zero is structural rather than opportunistic.

IsAuthorized is DERIVED, not stored, and that is a correctness property rather than a saving. With three independently settable flags, IsAuthorized = false alongside HasActivityGrant = true was expressible — a result asserting both that a grant exists and that the caller is unauthorized. Nothing rejected it and nothing could, because the inconsistency was in the data rather than in any code path. Computing it from the two grant flags makes that state unrepresentable.

Equality is written out rather than synthesized by a record, so the published surface carries exactly these members and no compiler-generated extras.

Properties

HasActivityGrant

Gets a value indicating whether the activity grant exists.

public bool HasActivityGrant { get; init; }

Property Value

bool

true if the activity grant exists; otherwise, false.

HasResourceGrant

Gets a value indicating whether the resource grant exists.

public bool HasResourceGrant { get; init; }

Property Value

bool

true if the resource grant exists; otherwise, false.

IsAuthorized

Gets a value indicating whether the activity is authorized.

public bool IsAuthorized { get; }

Property Value

bool

true if the activity is authorized; otherwise, false.

Remarks

Derived from HasActivityGrant and HasResourceGrant. Authorization is the existence of either grant, so this cannot disagree with them.

Methods

Equals(PolicyResult)

Indicates whether the current object is equal to another object of the same type.

public bool Equals(PolicyResult other)

Parameters

other PolicyResult

An object to compare with this object.

Returns

bool

true if the current object is equal to the other parameter; otherwise, false.

Equals(object?)

Indicates whether this instance and a specified object are equal.

public override bool Equals(object? obj)

Parameters

obj object

The object to compare with the current instance.

Returns

bool

true if obj and this instance are the same type and represent the same value; otherwise, false.

GetHashCode()

Returns the hash code for this instance.

public override int GetHashCode()

Returns

int

A 32-bit signed integer that is the hash code for this instance.

Operators

operator ==(PolicyResult, PolicyResult)

Determines whether two results carry the same grants.

public static bool operator ==(PolicyResult left, PolicyResult right)

Parameters

left PolicyResult

The first result.

right PolicyResult

The second result.

Returns

bool

true if both grant flags match.

operator !=(PolicyResult, PolicyResult)

Determines whether two results carry different grants.

public static bool operator !=(PolicyResult left, PolicyResult right)

Parameters

left PolicyResult

The first result.

right PolicyResult

The second result.

Returns

bool

true if either grant flag differs.