-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make CultureDictionaryRecordKey record struct (#15413)
- Loading branch information
Showing
4 changed files
with
11 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 4 additions & 48 deletions
52
src/OrchardCore/OrchardCore.Localization.Abstractions/CultureDictionaryRecordKey.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,26 @@ | ||
using System; | ||
|
||
namespace OrchardCore.Localization | ||
{ | ||
/// <summary> | ||
/// Represents a key for <see cref="CultureDictionaryRecord"/>. | ||
/// </summary> | ||
public readonly struct CultureDictionaryRecordKey : IEquatable<CultureDictionaryRecordKey> | ||
public readonly record struct CultureDictionaryRecordKey | ||
{ | ||
/// <summary> | ||
/// Creates new instance of <see cref="CultureDictionaryRecordKey"/>. | ||
/// </summary> | ||
/// <param name="messageId">The message Id.</param> | ||
public CultureDictionaryRecordKey(string messageId) : this(messageId, null) | ||
{ | ||
|
||
} | ||
|
||
/// <summary> | ||
/// Creates new instance of <see cref="CultureDictionaryRecordKey"/>. | ||
/// </summary> | ||
/// <param name="messageId">The message Id.</param> | ||
/// <param name="context">The message context.</param> | ||
public CultureDictionaryRecordKey(string messageId, string context) | ||
{ | ||
MessageId = messageId; | ||
Context = context; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the message Id. | ||
/// </summary> | ||
public string MessageId { get; } | ||
public required string MessageId { get; init; } | ||
|
||
/// <summary> | ||
/// Gets the message context. | ||
/// </summary> | ||
public string Context { get; } | ||
public string Context { get; init; } | ||
|
||
public static implicit operator string(CultureDictionaryRecordKey cultureDictionaryRecordKey) | ||
=> cultureDictionaryRecordKey.ToString(); | ||
|
||
/// <inheritdoc /> | ||
public override bool Equals(object obj) | ||
{ | ||
if (obj is CultureDictionaryRecordKey other) | ||
{ | ||
return Equals(other); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public bool Equals(CultureDictionaryRecordKey other) | ||
=> string.Equals(MessageId, other.MessageId) && String.Equals(Context, other.Context); | ||
|
||
/// <inheritdoc /> | ||
public override int GetHashCode() => HashCode.Combine(MessageId, Context); | ||
|
||
public override string ToString() | ||
=> string.IsNullOrEmpty(Context) | ||
? MessageId | ||
: Context.ToLowerInvariant() + "|" + MessageId; | ||
|
||
public static bool operator ==(CultureDictionaryRecordKey left, CultureDictionaryRecordKey right) => left.Equals(right); | ||
|
||
public static bool operator !=(CultureDictionaryRecordKey left, CultureDictionaryRecordKey right) => !(left == right); | ||
: $"{Context.ToLowerInvariant()}|{MessageId}"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters