Skip to content

Commit

Permalink
Resolve missing triple-slash in Microsoft.Extensions.Primitives (#76098)
Browse files Browse the repository at this point in the history
* Add triple slash in missing areas

* Apply suggestions from code review

Co-authored-by: Carlos Sanchez <[email protected]>

* Rewrite StringSegmentCompare GetHashCode() summary

* implement GetHashCode() feedback

* change instances to objects

Co-authored-by: Carlos Sanchez <[email protected]>
  • Loading branch information
Nick-Stanton and carlossanlop authored Sep 26, 2022
1 parent 3f0106a commit b914bb6
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Diagnostics;
using System.Threading;

namespace Microsoft.Extensions.Primitives
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

namespace Microsoft.Extensions.Primitives
{
/// <summary>
/// Provides extensions methods for the <see cref="Primitives"/> namespace.
/// </summary>
public static class Extensions
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,20 @@

namespace Microsoft.Extensions.Primitives
{
/// <summary>
/// Compares two <see cref="StringSegment"/> objects.
/// </summary>
public class StringSegmentComparer : IComparer<StringSegment>, IEqualityComparer<StringSegment>
{
/// <summary>
/// Gets a <see cref="StringSegmentComparer"/> object that performs a case-sensitive ordinal <see cref="StringSegment"/> comparison.
/// </summary>
public static StringSegmentComparer Ordinal { get; }
= new StringSegmentComparer(StringComparison.Ordinal, StringComparer.Ordinal);

/// <summary>
/// Gets a <see cref="StringSegmentComparer"/> object that performs a case-insensitive ordinal <see cref="StringSegment"/> comparison.
/// </summary>
public static StringSegmentComparer OrdinalIgnoreCase { get; }
= new StringSegmentComparer(StringComparison.OrdinalIgnoreCase, StringComparer.OrdinalIgnoreCase);

Expand All @@ -33,6 +42,11 @@ public bool Equals(StringSegment x, StringSegment y)
return StringSegment.Equals(x, y, Comparison);
}

/// <summary>
/// Returns a hash code for a <see cref="StringSegment"/> object.
/// </summary>
/// <param name="obj">The <see cref="StringSegment"/> to get a hash code for.</param>
/// <returns>A hash code for a <see cref="StringSegment"/>, suitable for use in hashing algorithms and data structures like a hash table.</returns>
public int GetHashCode(StringSegment obj)
{
#if NETCOREAPP || NETSTANDARD2_1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Microsoft.Extensions.Primitives
/// <summary>
/// Tokenizes a <see cref="string"/> into <see cref="StringSegment"/>s.
/// </summary>
public readonly struct StringTokenizer : IEnumerable<StringSegment>
public readonly struct StringTokenizer : IEnumerable<StringSegment>
{
private readonly StringSegment _value;
private readonly char[] _separators;
Expand Down Expand Up @@ -57,12 +57,19 @@ public StringTokenizer(StringSegment value, char[] separators)
_separators = separators;
}

/// <summary>
/// Initializes a new instance of <see cref="Enumerator"/>.
/// </summary>
/// <returns>An <see cref="Enumerator"/> based on the <see cref="StringTokenizer"/>'s value and separators.</returns>
public Enumerator GetEnumerator() => new Enumerator(in _value, _separators);

IEnumerator<StringSegment> IEnumerable<StringSegment>.GetEnumerator() => GetEnumerator();

IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();

/// <summary>
/// Enumerates the <see cref="string"/> tokens represented by <see cref="StringSegment"/>.
/// </summary>
public struct Enumerator : IEnumerator<StringSegment>
{
private readonly StringSegment _value;
Expand All @@ -77,6 +84,10 @@ internal Enumerator(in StringSegment value, char[] separators)
_index = 0;
}

/// <summary>
/// Initializes an <see cref="Enumerator"/> using a <see cref="StringTokenizer"/>.
/// </summary>
/// <param name="tokenizer"><see cref="StringTokenizer"/> containing value and separators for enumeration.</param>
public Enumerator(ref StringTokenizer tokenizer)
{
_value = tokenizer._value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,12 @@ public override bool Equals(object? obj)
return false;
}

/// <inheritdoc />
/// <summary>
/// Returns a hash code for this instance.
/// </summary>
/// <returns>
/// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
/// </returns>
public override int GetHashCode()
{
object? value = _values;
Expand Down Expand Up @@ -774,6 +779,10 @@ internal Enumerator(object? value)
_index = 0;
}

/// <summary>
/// Instantiates an <see cref="Enumerator"/> using a <see cref="StringValues"/>.
/// </summary>
/// <param name="values">The <see cref="StringValues"/> to enumerate.</param>
public Enumerator(ref StringValues values) : this(values._values)
{ }

Expand Down

0 comments on commit b914bb6

Please sign in to comment.