Background and Motivation
It would be nice if there was a singleton Empty property for BinaryData, which wraps an empty array. Without this, everyone who wants to return BinaryData needs to create the own static copy of an empty binary data, if they want to share this instance instead of allocating a new empty binary data each time.
Proposed API
Please provide the specific public API signature diff that you are proposing. For example:
namespace System
{
public class BinaryData {
+ public static BinaryData Empty { get; }
}
}
Usage Examples
Before
private static readonly s_EmptyBinaryData = new BinaryData(Array.Empty<byte>());
public BinaryData SomeMethodThatReturnsData() {
if ( /* some check that sees if there's any data to return */) {
return s_EmptyBinaryData;
}
}
(or, even worse, since we allocate each time!)
public BinaryData SomeMethodThatReturnsData() {
if ( /* some check that sees if there's any data to return */) {
return new BinaryData(Array.Empty<byte>());
}
}
After
public BinaryData SomeMethodThatReturnsData() {
if ( /* some check that sees if there's any data to return */) {
return BinaryData.Empty;
}
}
Alternative Designs
We did not consider any alternate designs over a static get only property named Empty.
Risks
None Identified.
Background and Motivation
It would be nice if there was a singleton
Emptyproperty forBinaryData, which wraps an empty array. Without this, everyone who wants to returnBinaryDataneeds to create the own static copy of an empty binary data, if they want to share this instance instead of allocating a new empty binary data each time.Proposed API
Please provide the specific public API signature diff that you are proposing. For example:
namespace System { public class BinaryData { + public static BinaryData Empty { get; } } }Usage Examples
Before
(or, even worse, since we allocate each time!)
After
Alternative Designs
We did not consider any alternate designs over a static get only property named
Empty.Risks
None Identified.