Skip to content

Commit

Permalink
CSHARP-4089: Move TranslationContextData to be internal. (#748)
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesKovacs authored Mar 9, 2022
1 parent 89ea0e5 commit cd60f58
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 30 deletions.
10 changes: 7 additions & 3 deletions src/MongoDB.Driver/AggregateExpressionDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,15 @@ public sealed class ExpressionAggregateExpressionDefinition<TSource, TResult> :
/// </summary>
/// <param name="expression">The expression.</param>
/// <param name="translationOptions">The translation options.</param>
/// <param name="contextData">Any optional data for the TranslationContext.</param>
public ExpressionAggregateExpressionDefinition(
public ExpressionAggregateExpressionDefinition(Expression<Func<TSource, TResult>> expression, ExpressionTranslationOptions translationOptions)
: this(expression, translationOptions, null)
{
}

internal ExpressionAggregateExpressionDefinition(
Expression<Func<TSource, TResult>> expression,
ExpressionTranslationOptions translationOptions,
TranslationContextData contextData = null)
TranslationContextData contextData)
{
_expression = Ensure.IsNotNull(expression, nameof(expression));
_translationOptions = translationOptions; // can be null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,10 @@

namespace MongoDB.Driver.Linq.Linq3Implementation.Translators
{
/// <summary>
/// Represents arbitrary data for a LINQ3 translation context.
/// </summary>
public sealed class TranslationContextData
internal sealed class TranslationContextData
{
private readonly Dictionary<string, object> _data;

/// <summary>
/// Initializes a new instance of a TranslationContextData.
/// </summary>
public TranslationContextData()
: this(new Dictionary<string, object>())
{
Expand All @@ -38,36 +32,16 @@ private TranslationContextData(Dictionary<string, object> data)
_data = Ensure.IsNotNull(data, nameof(data));
}

/// <summary>
/// Gets a value.
/// </summary>
/// <typeparam name="TValue">The type of the value.</typeparam>
/// <param name="key">The key.</param>
/// <returns>The value.</returns>
public TValue GetValue<TValue>(string key)
{
return (TValue)_data[key];
}

/// <summary>
/// Gets a value or a default value if they key is not present.
/// </summary>
/// <typeparam name="TValue">The type of the value.</typeparam>
/// <param name="key">The key.</param>
/// <param name="defaultValue">The default value.</param>
/// <returns>The value.</returns>
public TValue GetValueOrDefault<TValue>(string key, TValue defaultValue)
{
return _data.TryGetValue(key, out var value) ? (TValue)value : defaultValue;
}

/// <summary>
/// Returns a new TranslationContextData with an additional value.
/// </summary>
/// <typeparam name="TValue">The type of the value.</typeparam>
/// <param name="key">The key.</param>
/// <param name="value">The value.</param>
/// <returns>A new TranslationContextData with an additional value</returns>
public TranslationContextData With<TValue>(string key, TValue value)
{
var clonedData = new Dictionary<string, object>(_data);
Expand Down

0 comments on commit cd60f58

Please sign in to comment.