Skip to content
Merged
Show file tree
Hide file tree
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
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