Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose CultureDictionaryRecordKey properties #11358

Merged
merged 2 commits into from
Feb 23, 2024
Merged
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ namespace OrchardCore.Localization
/// </summary>
public readonly struct CultureDictionaryRecordKey : IEquatable<CultureDictionaryRecordKey>
{
private readonly string _messageId;
private readonly string _context;

/// <summary>
/// Creates new instance of <see cref="CultureDictionaryRecordKey"/>.
/// </summary>
Expand All @@ -26,10 +23,20 @@ public CultureDictionaryRecordKey(string messageId) : this(messageId, null)
/// <param name="context">The message context.</param>
public CultureDictionaryRecordKey(string messageId, string context)
{
_messageId = messageId;
_context = context;
MessageId = messageId;
Context = context;
}

/// <summary>
/// Gets the message Id.
/// </summary>
public string MessageId { get; }

/// <summary>
/// Gets the message context.
/// </summary>
public string Context { get; }

public static implicit operator string(CultureDictionaryRecordKey cultureDictionaryRecordKey)
=> cultureDictionaryRecordKey.ToString();

Expand All @@ -46,15 +53,15 @@ public override bool Equals(object obj)

/// <inheritdoc />
public bool Equals(CultureDictionaryRecordKey other)
=> string.Equals(_messageId, other._messageId) && string.Equals(_context, other._context);
=> string.Equals(MessageId, other.MessageId) && String.Equals(Context, other.Context);

/// <inheritdoc />
public override int GetHashCode() => HashCode.Combine(_messageId, _context);
public override int GetHashCode() => HashCode.Combine(MessageId, Context);

public override string ToString()
=> string.IsNullOrEmpty(_context)
? _messageId
: _context.ToLowerInvariant() + "|" + _messageId;
=> string.IsNullOrEmpty(Context)
? MessageId
: Context.ToLowerInvariant() + "|" + MessageId;

public static bool operator ==(CultureDictionaryRecordKey left, CultureDictionaryRecordKey right) => left.Equals(right);

Expand Down
Loading