[ 
https://issues.apache.org/jira/browse/TINKERPOP-1752?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16179215#comment-16179215
 ] 

ASF GitHub Bot commented on TINKERPOP-1752:
-------------------------------------------

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.


> Gremlin.Net: Generate completely type-safe methods
> --------------------------------------------------
>
>                 Key: TINKERPOP-1752
>                 URL: https://issues.apache.org/jira/browse/TINKERPOP-1752
>             Project: TinkerPop
>          Issue Type: Improvement
>          Components: dotnet
>    Affects Versions: 3.2.5
>            Reporter: Florian Hockmann
>            Priority: Minor
>
> Currently the generated traversal methods in Gremlin.Net take {{params 
> object[] args}} as an argument which allows the user to provide an arbitrary 
> number of arguments with any type. While this makes the generation rather 
> simple, it doesn't tell the user which arguments are actually valid so users 
> can submit completely invalid traversals like:
> {code}
> g.V(1).AddE(1234, "invalidArgument2").Next()
> {code}
> Type-safe methods could also use the original argument names to tell users 
> something about what kind of values the methods expect. Consider for example 
> the following method signatures for the C# step {{AddE}} that are basically a 
> 1:1 representation of the original Java {{addE}} step:
> {code}
> public GraphTraversal< S , Edge > AddE (Direction direction, string 
> firstVertexKeyOrEdgeLabel, string edgeLabelOrSecondVertexKey, params object[] 
> propertyKeyValues);
> public GraphTraversal< S , Edge > AddE (string edgeLabel);
> {code}
> Implementing this should make TINKERPOP-1725 obsolete and also resolve 
> TINKERPOP-1751.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to