Skip to content

Commit

Permalink
Adds ValueAsString helper to DnsCaaResource.
Browse files Browse the repository at this point in the history
  • Loading branch information
alanedwardes committed Mar 31, 2024
1 parent d8f2404 commit 0f520ee
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/Ae.Dns.Protocol/Records/DnsCaaResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@ public sealed class DnsCaaResource : IDnsResource, IEquatable<DnsCaaResource>
/// </summary>
public ReadOnlyMemory<byte> Value { get; set; }

/// <summary>
/// If this value is known to be a string, return it as ASCII.
/// </summary>
public string ValueAsString
{
get
{
#if NETSTANDARD2_0
return Encoding.ASCII.GetString(Value.ToArray());
#else
return Encoding.ASCII.GetString(Value.Span);
#endif
}
}

/// <inheritdoc/>
public bool Equals(DnsCaaResource? other)
{
Expand Down Expand Up @@ -57,7 +72,7 @@ public void ReadBytes(ReadOnlyMemory<byte> bytes, ref int offset, int length)
}

/// <inheritdoc/>
public override string ToString() => $"{Flag} {Tag} {Encoding.ASCII.GetString(Value.ToArray())}";
public override string ToString() => $"{Flag} {Tag} {ValueAsString}";

/// <inheritdoc/>
public void WriteBytes(Memory<byte> bytes, ref int offset)
Expand Down

0 comments on commit 0f520ee

Please sign in to comment.