Class EntityTagValue
- Namespace
- Trellis
- Assembly
- Trellis.Results.dll
Represents an RFC 9110 §8.8.1 entity tag (ETag) value with explicit weak/strong semantics.
public sealed record EntityTagValue : IEquatable<EntityTagValue>
- Inheritance
-
EntityTagValue
- Implements
- Inherited Members
- Extension Methods
Examples
var strong = EntityTagValue.Strong("abc123");
var weak = EntityTagValue.Weak("abc123");
// Parse from header
var parsed = EntityTagValue.TryParse("W/\"abc123\"");
// RFC 9110 §8.8.3.2 comparison
strong.StrongEquals(EntityTagValue.Strong("abc123")); // true
strong.WeakEquals(weak); // true
Remarks
An entity tag consists of an opaque quoted string, optionally prefixed with a weakness
indicator (W/). Entity tags are used for conditional requests and cache validation.
Create instances using Strong(string) or Weak(string) factory methods, or parse from header values using TryParse(string?). Compare using StrongEquals(EntityTagValue) or WeakEquals(EntityTagValue) per RFC 9110 §8.8.3.2. Format for HTTP headers using ToHeaderValue().
Properties
IsWeak
Gets whether this is a weak entity tag.
public bool IsWeak { get; }
Property Value
- bool
trueif weak;falseif strong.
IsWildcard
Gets whether this instance represents the RFC 9110 wildcard token
(as opposed to a literal ETag with opaque-tag ).
public bool IsWildcard { get; }
Property Value
OpaqueTag
Gets the raw opaque tag string without quotes or W/ prefix.
public string OpaqueTag { get; }
Property Value
Methods
Strong(string)
Creates a strong entity tag.
public static EntityTagValue Strong(string opaqueTag)
Parameters
opaqueTagstringThe opaque tag string.
Returns
- EntityTagValue
A new strong EntityTagValue.
StrongEquals(EntityTagValue)
Performs a strong comparison per RFC 9110 §8.8.3.2. Both tags must be strong and their opaque tags must match character-by-character. Wildcards never match in entity tag comparison — they are a precondition token, not a tag.
public bool StrongEquals(EntityTagValue other)
Parameters
otherEntityTagValue
Returns
ToHeaderValue()
Formats this entity tag for use in an HTTP header.
Returns * for the wildcard, "tag" for strong tags, or W/"tag" for weak tags.
public string ToHeaderValue()
Returns
- string
The formatted HTTP header value.
ToString()
Returns a string that represents the current object.
public override string ToString()
Returns
- string
A string that represents the current object.
TryParse(string?)
Parses an entity tag from its HTTP header representation.
public static Result<EntityTagValue> TryParse(string? headerValue)
Parameters
headerValuestringThe header value to parse. Expected formats:
"tag"for strong orW/"tag"for weak.
Returns
- Result<EntityTagValue>
A Result<TValue> containing the parsed EntityTagValue on success, or a BadRequestError on failure.
Examples
var strong = EntityTagValue.TryParse("\"abc123\"");
var weak = EntityTagValue.TryParse("W/\"abc123\"");
Weak(string)
Creates a weak entity tag.
public static EntityTagValue Weak(string opaqueTag)
Parameters
opaqueTagstringThe opaque tag string.
Returns
- EntityTagValue
A new weak EntityTagValue.
WeakEquals(EntityTagValue)
Performs a weak comparison per RFC 9110 §8.8.3.2. Only the opaque tags must match; the weakness indicator is ignored. Wildcards never match in entity tag comparison — they are a precondition token, not a tag.
public bool WeakEquals(EntityTagValue other)
Parameters
otherEntityTagValue
Returns
Wildcard()
Creates the RFC 9110 wildcard entity tag (), which matches any current entity.
This is semantically distinct from Strong(""), which is a literal ETag with opaque-tag *.
public static EntityTagValue Wildcard()
Returns
- EntityTagValue
A wildcard EntityTagValue.