StringSegmentComparer Class

Represents a string comparison operation that uses specific case and culture-based or ordinal comparison rules allowing comparing strings by string, StringSegment and ReadOnlySpan<char> instances.
See the static properties for more details.

Definition

Namespace: KGySoft.CoreLibraries
Assembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 9.0.0
C#
[SerializableAttribute]
public abstract class StringSegmentComparer : IEqualityComparer<StringSegment>, 
	IComparer<StringSegment>, IEqualityComparer<string>, IComparer<string>, 
	IAlternateEqualityComparer<StringSegment, string>, IAlternateEqualityComparer<ReadOnlySpan<char>, string>, 
	IEqualityComparer, IComparer
Inheritance
Object    StringSegmentComparer
Implements
IAlternateEqualityComparerStringSegment, String, IAlternateEqualityComparerReadOnlySpanChar, String, IComparerStringSegment, IComparerString, IEqualityComparerStringSegment, IEqualityComparerString, IComparer, IEqualityComparer

Remarks

This class exists to support lookup operations by StringSegment and ReadOnlySpan<char> instances for IStringKeyedDictionaryTValue and IStringKeyedReadOnlyDictionaryTValue implementations, such as the StringKeyedDictionaryTValue class.

Actually you can use this comparer anywhere where you would just use a StringComparer. Some members may provide bette performance or improved functionality than the regular StringComparer members, especially on older platforms.

Constructors

StringSegmentComparerInitializes a new instance of the StringSegmentComparer class

Properties

CompareInfo Gets a CompareInfo that is associated with this StringSegmentComparer or if this StringSegmentComparer is not a culture-aware one.
CompareOptions Gets the CompareOptions that is associated with this StringSegmentComparer.
CurrentCulture Gets a StringSegmentComparer object that performs a case-sensitive string comparison using the word comparison rules of the current culture.
Depending on the targeted platform, the GetHashCode(StringSegment) method might allocate a new string. In .NET Core 3.0 and above none of the members of the returned StringSegmentComparer will allocate new strings.
CurrentCultureIgnoreCase Gets a StringSegmentComparer object that performs case-insensitive string comparisons using the word comparison rules of the current culture.
Depending on the targeted platform, the GetHashCode(StringSegment) method might allocate a new string. In .NET Core 3.0 and above none of the members of the returned StringSegmentComparer will allocate new strings.
InvariantCulture Gets a StringSegmentComparer object that performs a case-sensitive string comparison using the word comparison rules of the invariant culture.
Depending on the targeted platform, the GetHashCode(StringSegment) method might allocate a new string. In .NET Core 3.0 and above none of the members of the returned StringSegmentComparer will allocate new strings.
InvariantCultureIgnoreCase Gets a StringSegmentComparer object that performs a case-insensitive string comparison using the word comparison rules of the invariant culture.
Depending on the targeted platform, the GetHashCode(StringSegment) method might allocate a new string. In .NET Core 3.0 and above none of the members of the returned StringSegmentComparer will allocate new strings.
Ordinal Gets a StringSegmentComparer object that performs a case-sensitive ordinal string comparison.
The methods of the returned StringSegmentComparer instance can be called with string, StringSegment and ReadOnlySpan<char> parameter values, which will not allocate new strings on any platform.
OrdinalIgnoreCase Gets a StringSegmentComparer object that performs a case-insensitive ordinal string comparison.
The methods of the returned StringSegmentComparer instance can be called with string, StringSegment and ReadOnlySpan<char> parameter values, which will not allocate new strings on any platform.
OrdinalIgnoreCaseNonRandomized Gets a StringSegmentComparer object that performs a case-insensitive ordinal string comparison. The returned comparer is functionally equivalent with OrdinalIgnoreCase but it ensures that the hash code of a specific string is stable only within the same process and AppDomain.
OrdinalIgnoreCaseRandomized Gets a StringSegmentComparer object that performs a case-insensitive ordinal string comparison. The returned comparer is functionally equivalent with OrdinalIgnoreCase but it ensures that the hash code of a specific string is stable only within the same process and AppDomain.
OrdinalNonRandomized Gets a StringSegmentComparer object that performs a case-sensitive ordinal string comparison. The returned comparer is functionally equivalent with Ordinal but it ensures that the hash code of a specific string is always the same, regardless of the targeted platform or the length of the string.
OrdinalRandomized Gets a StringSegmentComparer object that performs a case-sensitive ordinal string comparison. The returned comparer is functionally equivalent with Ordinal but it ensures that the hash code of a specific string is stable only within the same process and AppDomain.

Methods

Compare(Object, Object) When overridden in a derived class, compares two objects and returns an indication of their relative sort order.
Compare(ReadOnlySpanChar, ReadOnlySpanChar) When overridden in a derived class, compares two ReadOnlySpan<char> instances and returns an indication of their relative sort order.
Compare(String, String) When overridden in a derived class, compares two string instances and returns an indication of their relative sort order.
Compare(StringSegment, StringSegment) When overridden in a derived class, compares two StringSegment instances and returns an indication of their relative sort order.
Create(CultureInfo, Boolean) Creates a StringSegmentComparer object that compares strings according to the rules of a specified culture.
Please note that the returned StringSegmentComparer may allocate new strings in some cases when targeting older frameworks. See the Remarks section for details.
Create(CultureInfo, CompareOptions) Creates a StringSegmentComparer object that compares strings according to the rules of a specified culture.
Please note that the returned StringSegmentComparer may allocate new strings in some cases when targeting older frameworks. See the Remarks section for details.
Equals(Object, Object) When overridden in a derived class, indicates whether two objects are equal.
Equals(ReadOnlySpanChar, ReadOnlySpanChar) When overridden in a derived class, indicates whether two ReadOnlySpan<char> instances are equal.
Equals(String, String) When overridden in a derived class, indicates whether two string instances are equal.
Equals(StringSegment, StringSegment) When overridden in a derived class, indicates whether two StringSegment instances are equal.
FromComparison Gets a StringSegmentComparer instance based on the specified comparison.
Please note that the returned StringSegmentComparer may allocate new strings in some cases. See the description of the properties for more details.
GetHashCode(Object) When overridden in a derived class, gets the hash code for the specified object.
GetHashCode(ReadOnlySpanChar) When overridden in a derived class, gets the hash code for the specified ReadOnlySpan<char>.
GetHashCode(String) When overridden in a derived class, gets the hash code for the specified string.
GetHashCode(StringSegment) When overridden in a derived class, gets the hash code for the specified StringSegment.

Extension Methods

Convert Converts an Object specified in the obj parameter to the desired targetType.
See the Examples section of the generic ConvertTTarget(Object, CultureInfo) overload for an example.
(Defined by ObjectExtensions)
ConvertTTarget Converts an Object specified in the obj parameter to the desired TTarget.
(Defined by ObjectExtensions)
In Gets whether item is among the elements of set.
See the Examples section of the generic InT(T, T) overload for an example.
(Defined by ObjectExtensions)
TryConvert Tries to convert an Object specified in the obj parameter to the desired targetType.
See the Examples section of the ConvertTTarget(Object, CultureInfo) method for a related example.
(Defined by ObjectExtensions)
TryConvert Tries to convert an Object specified in the obj parameter to the desired targetType.
See the Examples section of the ConvertTTarget(Object, CultureInfo) method for a related example.
(Defined by ObjectExtensions)
TryConvertTTarget Tries to convert an Object specified in the obj parameter to the desired TTarget.
See the Examples section of the ConvertTTarget(Object, CultureInfo) method for a related example.
(Defined by ObjectExtensions)
TryConvertTTarget Tries to convert an Object specified in the obj parameter to the desired TTarget.
See the Examples section of the ConvertTTarget(Object, CultureInfo) method for a related example.
(Defined by ObjectExtensions)

See Also