Github user jorgebay commented on a diff in the pull request: https://github.com/apache/tinkerpop/pull/712#discussion_r140818845 --- Diff: gremlin-dotnet/src/Gremlin.Net/Process/Traversal/Bindings.cs --- @@ -29,14 +32,42 @@ namespace Gremlin.Net.Process.Traversal public class Bindings { /// <summary> + /// Gets an instance of the <see cref="Bindings" /> class. + /// </summary> + public static Bindings Instance { get; } = new Bindings(); + + private static readonly ThreadLocal<Dictionary<object, string>> BoundVariableByValue = + new ThreadLocal<Dictionary<object, string>>(); + + /// <summary> /// Binds the variable to the specified value. /// </summary> /// <param name="variable">The variable to bind.</param> /// <param name="value">The value to which the variable should be bound.</param> /// <returns>The bound value.</returns> - public Binding Of(string variable, object value) + public TV Of<TV>(string variable, TV value) + { + var dict = BoundVariableByValue.Value; + if (dict == null) + { + dict = new Dictionary<object, string>(); + BoundVariableByValue.Value = dict; + } + dict[value] = variable; + return value; + } + + internal static string GetBoundVariable<TV>(TV value) + { + var dict = BoundVariableByValue.Value; + if (dict == null) + return null; + return !dict.ContainsKey(value) ? null : dict[value]; --- End diff -- Use `Dictionary{K, V}.TryGetValue()` to save one operation.
---