Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Anotate ref
  • Loading branch information
maxkoshevoi committed Aug 14, 2021
commit 31b9391b7281dcbc1f87ed5404eb12445ae26a1f
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
// Changes to this file must follow the https://aka.ms/api-review process.
// ------------------------------------------------------------------------------

using System.Diagnostics.CodeAnalysis;

namespace Microsoft.Extensions.Primitives
{
public partial class CancellationChangeToken : Microsoft.Extensions.Primitives.IChangeToken
{
public CancellationChangeToken(System.Threading.CancellationToken cancellationToken) { }
public bool ActiveChangeCallbacks { get { throw null; } }
public bool HasChanged { get { throw null; } }
public System.IDisposable RegisterChangeCallback(System.Action<object> callback, object state) { throw null; }
public System.IDisposable RegisterChangeCallback(System.Action<object?> callback, object? state) { throw null; }
}
public static partial class ChangeToken
{
Expand All @@ -24,7 +26,7 @@ public CompositeChangeToken(System.Collections.Generic.IReadOnlyList<Microsoft.E
public bool ActiveChangeCallbacks { get { throw null; } }
public System.Collections.Generic.IReadOnlyList<Microsoft.Extensions.Primitives.IChangeToken> ChangeTokens { get { throw null; } }
public bool HasChanged { get { throw null; } }
public System.IDisposable RegisterChangeCallback(System.Action<object> callback, object state) { throw null; }
public System.IDisposable RegisterChangeCallback(System.Action<object?> callback, object? state) { throw null; }
}
public static partial class Extensions
{
Expand All @@ -34,7 +36,7 @@ public partial interface IChangeToken
{
bool ActiveChangeCallbacks { get; }
bool HasChanged { get; }
System.IDisposable RegisterChangeCallback(System.Action<object> callback, object state);
System.IDisposable RegisterChangeCallback(System.Action<object?> callback, object? state);
}
public readonly partial struct StringSegment : System.IEquatable<Microsoft.Extensions.Primitives.StringSegment>, System.IEquatable<string>
{
Expand All @@ -44,11 +46,12 @@ public partial interface IChangeToken
public StringSegment(string buffer) { throw null; }
public StringSegment(string buffer, int offset, int length) { throw null; }
public string Buffer { get { throw null; } }
[MemberNotNullWhen(true, nameof(Buffer))]
public bool HasValue { get { throw null; } }
public char this[int index] { get { throw null; } }
public int Length { get { throw null; } }
public int Offset { get { throw null; } }
public string Value { get { throw null; } }
public string? Value { get { throw null; } }
public System.ReadOnlyMemory<char> AsMemory() { throw null; }
public System.ReadOnlySpan<char> AsSpan() { throw null; }
public System.ReadOnlySpan<char> AsSpan(int start) { throw null; }
Expand All @@ -58,8 +61,8 @@ public partial interface IChangeToken
public bool Equals(Microsoft.Extensions.Primitives.StringSegment other) { throw null; }
public static bool Equals(Microsoft.Extensions.Primitives.StringSegment a, Microsoft.Extensions.Primitives.StringSegment b, System.StringComparison comparisonType) { throw null; }
public bool Equals(Microsoft.Extensions.Primitives.StringSegment other, System.StringComparison comparisonType) { throw null; }
public override bool Equals(object obj) { throw null; }
public bool Equals(string text) { throw null; }
public override bool Equals(object? obj) { throw null; }
public bool Equals(string? text) { throw null; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this throw for null?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't allow me to make it non-nullable...

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interestingly, in implementation text is non-nullable and everything compiles fine

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't allow me to make it non-nullable...

You need to change the type of the interface being implemented to IEquatable<string?>.

in implementation text is non-nullable and everything compiles fine

Yes, because the code never tries to dereference a maybe-null value. The first thing the code does is check whether it's null and throw if it is.

Copy link
Contributor Author

@maxkoshevoi maxkoshevoi Aug 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to change the type of the interface being implemented to IEquatable<string?>

Still doesn't allow non-nullable text

image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I misread what you'd written. IEquatable<T> is defined to expect Equals always allows null (it accepts a T?), which is why this is complaining about trying to specify a non-nullable value. I think the implementation should be changed to return false rather than throwing, and then typed as string?, but I'll defer here to @dotnet/area-microsoft-extensions area owners.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made it return false.

public bool Equals(string text, System.StringComparison comparisonType) { throw null; }
public override int GetHashCode() { throw null; }
public int IndexOf(char c) { throw null; }
Expand All @@ -71,9 +74,9 @@ public partial interface IChangeToken
public static bool IsNullOrEmpty(Microsoft.Extensions.Primitives.StringSegment value) { throw null; }
public int LastIndexOf(char value) { throw null; }
public static bool operator ==(Microsoft.Extensions.Primitives.StringSegment left, Microsoft.Extensions.Primitives.StringSegment right) { throw null; }
public static implicit operator System.ReadOnlyMemory<char> (Microsoft.Extensions.Primitives.StringSegment segment) { throw null; }
public static implicit operator System.ReadOnlySpan<char> (Microsoft.Extensions.Primitives.StringSegment segment) { throw null; }
public static implicit operator Microsoft.Extensions.Primitives.StringSegment (string value) { throw null; }
public static implicit operator System.ReadOnlyMemory<char>(Microsoft.Extensions.Primitives.StringSegment segment) { throw null; }
public static implicit operator System.ReadOnlySpan<char>(Microsoft.Extensions.Primitives.StringSegment segment) { throw null; }
public static implicit operator Microsoft.Extensions.Primitives.StringSegment(string value) { throw null; }
public static bool operator !=(Microsoft.Extensions.Primitives.StringSegment left, Microsoft.Extensions.Primitives.StringSegment right) { throw null; }
public Microsoft.Extensions.Primitives.StringTokenizer Split(char[] chars) { throw null; }
public bool StartsWith(string text, System.StringComparison comparisonType) { throw null; }
Expand Down Expand Up @@ -116,49 +119,49 @@ public void Dispose() { }
public void Reset() { }
}
}
public readonly partial struct StringValues : System.Collections.Generic.ICollection<string>, System.Collections.Generic.IEnumerable<string>, System.Collections.Generic.IList<string>, System.Collections.Generic.IReadOnlyCollection<string>, System.Collections.Generic.IReadOnlyList<string>, System.Collections.IEnumerable, System.IEquatable<Microsoft.Extensions.Primitives.StringValues>, System.IEquatable<string>, System.IEquatable<string[]>
public readonly partial struct StringValues : System.Collections.Generic.ICollection<string>, System.Collections.Generic.IEnumerable<string>, System.Collections.Generic.IList<string>, System.Collections.Generic.IReadOnlyCollection<string>, System.Collections.Generic.IReadOnlyList<string>, System.Collections.IEnumerable, System.IEquatable<Microsoft.Extensions.Primitives.StringValues>, System.IEquatable<string?>, System.IEquatable<string[]>
{
private readonly object _dummy;
private readonly int _dummyPrimitive;
public static readonly Microsoft.Extensions.Primitives.StringValues Empty;
public StringValues(string value) { throw null; }
public StringValues(string? value) { throw null; }
public StringValues(string[] values) { throw null; }
public int Count { get { throw null; } }
public string this[int index] { get { throw null; } }
bool System.Collections.Generic.ICollection<System.String>.IsReadOnly { get { throw null; } }
string System.Collections.Generic.IList<System.String>.this[int index] { get { throw null; } set { } }
public static Microsoft.Extensions.Primitives.StringValues Concat(Microsoft.Extensions.Primitives.StringValues values1, Microsoft.Extensions.Primitives.StringValues values2) { throw null; }
public static Microsoft.Extensions.Primitives.StringValues Concat(in Microsoft.Extensions.Primitives.StringValues values, string value) { throw null; }
public static Microsoft.Extensions.Primitives.StringValues Concat(string value, in Microsoft.Extensions.Primitives.StringValues values) { throw null; }
public static Microsoft.Extensions.Primitives.StringValues Concat(in Microsoft.Extensions.Primitives.StringValues values, string? value) { throw null; }
public static Microsoft.Extensions.Primitives.StringValues Concat(string? value, in Microsoft.Extensions.Primitives.StringValues values) { throw null; }
public bool Equals(Microsoft.Extensions.Primitives.StringValues other) { throw null; }
public static bool Equals(Microsoft.Extensions.Primitives.StringValues left, Microsoft.Extensions.Primitives.StringValues right) { throw null; }
public static bool Equals(Microsoft.Extensions.Primitives.StringValues left, string right) { throw null; }
public static bool Equals(Microsoft.Extensions.Primitives.StringValues left, string? right) { throw null; }
public static bool Equals(Microsoft.Extensions.Primitives.StringValues left, string[] right) { throw null; }
public override bool Equals(object obj) { throw null; }
public bool Equals(string other) { throw null; }
public static bool Equals(string left, Microsoft.Extensions.Primitives.StringValues right) { throw null; }
public bool Equals(string[] other) { throw null; }
public override bool Equals(object? obj) { throw null; }
public bool Equals(string? other) { throw null; }
public static bool Equals(string? left, Microsoft.Extensions.Primitives.StringValues right) { throw null; }
public bool Equals(string[]? other) { throw null; }
public static bool Equals(string[] left, Microsoft.Extensions.Primitives.StringValues right) { throw null; }
public Microsoft.Extensions.Primitives.StringValues.Enumerator GetEnumerator() { throw null; }
public override int GetHashCode() { throw null; }
public static bool IsNullOrEmpty(Microsoft.Extensions.Primitives.StringValues value) { throw null; }
public static bool operator ==(Microsoft.Extensions.Primitives.StringValues left, Microsoft.Extensions.Primitives.StringValues right) { throw null; }
public static bool operator ==(Microsoft.Extensions.Primitives.StringValues left, object right) { throw null; }
public static bool operator ==(Microsoft.Extensions.Primitives.StringValues left, string right) { throw null; }
public static bool operator ==(Microsoft.Extensions.Primitives.StringValues left, string? right) { throw null; }
public static bool operator ==(Microsoft.Extensions.Primitives.StringValues left, string[] right) { throw null; }
public static bool operator ==(object left, Microsoft.Extensions.Primitives.StringValues right) { throw null; }
public static bool operator ==(string left, Microsoft.Extensions.Primitives.StringValues right) { throw null; }
public static bool operator ==(string? left, Microsoft.Extensions.Primitives.StringValues right) { throw null; }
public static bool operator ==(string[] left, Microsoft.Extensions.Primitives.StringValues right) { throw null; }
public static implicit operator string (Microsoft.Extensions.Primitives.StringValues values) { throw null; }
public static implicit operator string[] (Microsoft.Extensions.Primitives.StringValues value) { throw null; }
public static implicit operator Microsoft.Extensions.Primitives.StringValues (string value) { throw null; }
public static implicit operator Microsoft.Extensions.Primitives.StringValues (string[] values) { throw null; }
public static implicit operator string?(Microsoft.Extensions.Primitives.StringValues values) { throw null; }
public static implicit operator string[](Microsoft.Extensions.Primitives.StringValues value) { throw null; }
public static implicit operator Microsoft.Extensions.Primitives.StringValues(string? value) { throw null; }
public static implicit operator Microsoft.Extensions.Primitives.StringValues(string[] values) { throw null; }
public static bool operator !=(Microsoft.Extensions.Primitives.StringValues left, Microsoft.Extensions.Primitives.StringValues right) { throw null; }
public static bool operator !=(Microsoft.Extensions.Primitives.StringValues left, object right) { throw null; }
public static bool operator !=(Microsoft.Extensions.Primitives.StringValues left, string right) { throw null; }
public static bool operator !=(Microsoft.Extensions.Primitives.StringValues left, string? right) { throw null; }
public static bool operator !=(Microsoft.Extensions.Primitives.StringValues left, string[] right) { throw null; }
public static bool operator !=(object left, Microsoft.Extensions.Primitives.StringValues right) { throw null; }
public static bool operator !=(string left, Microsoft.Extensions.Primitives.StringValues right) { throw null; }
public static bool operator !=(string? left, Microsoft.Extensions.Primitives.StringValues right) { throw null; }
public static bool operator !=(string[] left, Microsoft.Extensions.Primitives.StringValues right) { throw null; }
void System.Collections.Generic.ICollection<System.String>.Add(string item) { }
void System.Collections.Generic.ICollection<System.String>.Clear() { }
Expand All @@ -172,12 +175,12 @@ public void Reset() { }
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { throw null; }
public string[] ToArray() { throw null; }
public override string ToString() { throw null; }
public partial struct Enumerator : System.Collections.Generic.IEnumerator<string>, System.Collections.IEnumerator, System.IDisposable
public partial struct Enumerator : System.Collections.Generic.IEnumerator<string?>, System.Collections.IEnumerator, System.IDisposable
{
private object _dummy;
private int _dummyPrimitive;
public Enumerator(ref Microsoft.Extensions.Primitives.StringValues values) { throw null; }
public string Current { get { throw null; } }
public string? Current { get { throw null; } }
object System.Collections.IEnumerator.Current { get { throw null; } }
public void Dispose() { }
public bool MoveNext() { throw null; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>$(NetCoreAppCurrent);netcoreapp3.1;netstandard2.0;net461</TargetFrameworks>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Compile Include="Microsoft.Extensions.Primitives.cs" />
Expand Down