Exemple #1
0
            public virtual object GetIdentifier(Expression expression)
            {
                if (expression is MemberExpression memberExpression)
                {
                    var memberName = memberExpression.Member.Name;
                    var elementType = memberExpression.Expression.Type;

                    if (string.Equals(memberName, "id", StringComparison.OrdinalIgnoreCase) || string.Equals(memberName, "label", StringComparison.OrdinalIgnoreCase))
                    {
                        var graphElementType = ElementTypes
                            .GetOrCreateValue(this)
                            .GetOrAdd(
                                elementType,
                                closureElementType =>
                                {
                                    if (elementType == typeof(IVertex) || VerticesModel.TryGetConstructiveLabel(elementType).IsSome)
                                        return GraphElementType.Vertex;

                                    if (elementType == typeof(IEdge) || EdgesModel.TryGetConstructiveLabel(elementType).IsSome)
                                        return GraphElementType.Edge;

                                    return typeof(IVertexProperty).IsAssignableFrom(elementType)
                                        ? GraphElementType.VertexProperty
                                        : GraphElementType.None;
                                });

                        if (graphElementType != GraphElementType.None)
                        {
                            if (string.Equals(memberName, "id", StringComparison.OrdinalIgnoreCase))
                                return T.Id;

                            if (string.Equals(memberName, "label", StringComparison.OrdinalIgnoreCase))
                                return T.Label;
                        }
                    }

                    return memberName;
                }

                throw new ExpressionNotSupportedException(expression);
            }