HttpRange
Defines a range of bytes within an HTTP resource, starting at an offset and
ending at offset+count-1 inclusively.
using Azure.Core;
using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace Azure
{
public readonly struct HttpRange : IEquatable<HttpRange>
{
[System.Runtime.CompilerServices.Nullable(1)]
private const string Unit = "bytes";
public long Offset { get; }
public long? Length { get; }
public HttpRange(long offset = 0, long? length = default(long?))
{
if (offset < 0)
throw new ArgumentOutOfRangeException("offset");
if (length.HasValue) {
long? nullable = length;
long num = 0;
if ((nullable.GetValueOrDefault() <= num) & nullable.HasValue)
throw new ArgumentOutOfRangeException("length");
}
Offset = offset;
Length = length;
}
[System.Runtime.CompilerServices.NullableContext(1)]
public override string ToString()
{
if (Length.HasValue) {
long? length = Length;
long num = 0;
if (!((length.GetValueOrDefault() == num) & length.HasValue)) {
long num2 = Offset + Length.Value - 1;
return FormattableString.Invariant(FormattableStringFactory.Create("{0}={1}-{2}", "bytes", Offset, num2));
}
}
return FormattableString.Invariant(FormattableStringFactory.Create("{0}={1}-", "bytes", Offset));
}
public static bool operator ==(HttpRange left, HttpRange right)
{
return left.Equals(right);
}
public static bool operator !=(HttpRange left, HttpRange right)
{
return !(left == right);
}
public bool Equals(HttpRange other)
{
if (Offset == other.Offset) {
long? length = Length;
long? length2 = other.Length;
return (length.GetValueOrDefault() == length2.GetValueOrDefault()) & (length.HasValue == length2.HasValue);
}
return false;
}
[System.Runtime.CompilerServices.NullableContext(2)]
[EditorBrowsable(EditorBrowsableState.Never)]
public override bool Equals(object obj)
{
if (obj is HttpRange) {
HttpRange other = (HttpRange)obj;
return Equals(other);
}
return false;
}
[EditorBrowsable(EditorBrowsableState.Never)]
public override int GetHashCode()
{
return HashCodeBuilder.Combine(Offset, Length);
}
}
}