public static System.BinaryData FromString(string data) { throw null; }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public override int GetHashCode() { throw null; }
+ public bool IsEmpty { get { throw null; } }
+ public int Length { get { throw null; } }
public static implicit operator System.ReadOnlyMemory<byte> (System.BinaryData? data) { throw null; }
public static implicit operator System.ReadOnlySpan<byte> (System.BinaryData? data) { throw null; }
public byte[] ToArray() { throw null; }
public static BinaryData Empty { get; } = new BinaryData(ReadOnlyMemory<byte>.Empty);
/// <summary>
+ /// Gets the number of bytes of this data.
+ /// </summary>
+ /// <returns>The number of bytes of this data.</returns>
+ public int Length => _bytes.Length;
+
+ /// <summary>
+ /// Gets a value that indicates whether this data is empty.
+ /// </summary>
+ /// <returns><see langword="true" /> if the data is empty (that is, its <see cref="Length" /> is 0); otherwise, <see langword="false" />.</returns>
+ public bool IsEmpty => _bytes.IsEmpty;
+
+ /// <summary>
/// Creates a <see cref="BinaryData"/> instance by wrapping the
/// provided byte array.
/// </summary>
-// Licensed to the .NET Foundation under one or more agreements.
+// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
Assert.Equal(string.Empty, BinaryData.Empty.ToString());
}
+ [Theory]
+ [InlineData(0)]
+ [InlineData(4)]
+ [InlineData(7)]
+ public void LengthReturnsNumberOfBytesForBinaryDataFromReadOnlyMemory(int count)
+ {
+ var data = BinaryData.FromBytes(new ReadOnlyMemory<byte>(new byte[count]));
+ Assert.Equal(count, data.Length);
+ }
+
+ [Theory]
+ [InlineData(0)]
+ [InlineData(4)]
+ [InlineData(7)]
+ public void LengthReturnsNumberOfBytesForBinaryDataFromArray(int count)
+ {
+ var data = BinaryData.FromBytes(new byte[count]);
+ Assert.Equal(count, data.Length);
+ }
+
+ [Theory]
+ [InlineData(0)]
+ [InlineData(4)]
+ [InlineData(7)]
+ public void LengthReturnsNumberOfBytesForBinaryDataFromString(int count)
+ {
+ var data = BinaryData.FromString(new string('*', count));
+ Assert.Equal(count, data.Length);
+ }
+
+ [Fact]
+ public void BinaryDataEmptyIsEmpty()
+ {
+ Assert.True(BinaryData.Empty.IsEmpty);
+ }
+
+ [Fact]
+ public void BinaryDataFromEmptyReadOnlyMemoryIsEmpty()
+ {
+ var data = BinaryData.FromBytes(ReadOnlyMemory<byte>.Empty);
+ Assert.True(data.IsEmpty);
+ }
+
+ [Fact]
+ public void BinaryDataFromEmptyArrayIsEmpty()
+ {
+ var data = BinaryData.FromBytes(Array.Empty<byte>());
+ Assert.True(data.IsEmpty);
+ }
+
+ [Fact]
+ public void BinaryDataFromEmptyStringIsEmpty()
+ {
+ var data = BinaryData.FromString("");
+ Assert.True(data.IsEmpty);
+ }
+
+ [Theory]
+ [InlineData(1)]
+ [InlineData(4)]
+ [InlineData(7)]
+ public void NonEmptyBinaryDataFromReadOnlyMemoryIsNotEmpty(int count)
+ {
+ var data = BinaryData.FromBytes(new ReadOnlyMemory<byte>(new byte[count]));
+ Assert.False(data.IsEmpty);
+ }
+
+ [Theory]
+ [InlineData(1)]
+ [InlineData(4)]
+ [InlineData(7)]
+ public void NonEmptyBinaryDataFromArrayIsNotEmpty(int count)
+ {
+ var data = BinaryData.FromBytes(new byte[count]);
+ Assert.False(data.IsEmpty);
+ }
+
+ [Theory]
+ [InlineData(1)]
+ [InlineData(4)]
+ [InlineData(7)]
+ public void NonEmptyBinaryDataFromStringIsNotEmpty(int count)
+ {
+ var data = BinaryData.FromString(new string('*', count));
+ Assert.False(data.IsEmpty);
+ }
+
[Fact]
public void IsBinaryDataMemberPropertySerialized()
{