<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="10.0.0-rc.1.25451.107" />

Measurement<T>

public struct Measurement<T> where T : struct
Stores one observed metrics value and its associated tags. This type is used by an Observable instrument's Observe() method when reporting current measurements.
using System.Collections.Generic; using System.Linq; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace System.Diagnostics.Metrics { public readonly struct Measurement<T> where T : struct { private readonly KeyValuePair<string, object>[] _tags; [System.Runtime.CompilerServices.Nullable(new byte[] { 0, 0, 1, 2 })] public ReadOnlySpan<KeyValuePair<string, object>> Tags { [return: System.Runtime.CompilerServices.Nullable(new byte[] { 0, 0, 1, 2 })] get { return MemoryExtensions.AsSpan<KeyValuePair<string, object>>(_tags); } } public T Value { get; } public Measurement(T value) { _tags = Instrument.EmptyTags; Value = value; } public Measurement(T value, [System.Runtime.CompilerServices.Nullable(new byte[] { 2, 0, 1, 2 })] IEnumerable<KeyValuePair<string, object>> tags) { _tags = (((tags != null) ? Enumerable.ToArray<KeyValuePair<string, object>>(tags) : null) ?? Instrument.EmptyTags); Value = value; } public Measurement(T value, [System.Runtime.CompilerServices.Nullable(new byte[] { 2, 0, 1, 2 })] params KeyValuePair<string, object>[] tags) { if (tags != null) { _tags = new KeyValuePair<string, object>[tags.Length]; tags.CopyTo(_tags, 0); } else _tags = Instrument.EmptyTags; Value = value; } public Measurement(T value, [System.Runtime.CompilerServices.ParamCollection] [System.Runtime.CompilerServices.ScopedRef] [System.Runtime.CompilerServices.Nullable(new byte[] { 0, 0, 1, 2 })] ReadOnlySpan<KeyValuePair<string, object>> tags) { _tags = tags.ToArray(); Value = value; } public Measurement(T value, [In] [System.Runtime.CompilerServices.IsReadOnly] ref TagList tags) { if (tags.Count > 0) { _tags = new KeyValuePair<string, object>[tags.Count]; tags.CopyTo(MemoryExtensions.AsSpan<KeyValuePair<string, object>>(_tags)); } else _tags = Instrument.EmptyTags; Value = value; } } }