Exemple #1
0
        public static string ToPropertyPath(this Expression expression, char propertySeparator = '.', char collectionSeparator = ',')
        {
            var propertyPathExpressionVisitor = new PropertyPathExpressionVisitor(propertySeparator.ToString(), collectionSeparator.ToString());

            propertyPathExpressionVisitor.Visit(expression);

            var builder = new StringBuilder();

            var stackLength = propertyPathExpressionVisitor.Results.Count;

            for (var i = 0; i < stackLength; i++)
            {
                var curValue = propertyPathExpressionVisitor.Results.Pop();

                if (curValue.Length == 1 && curValue[0] == propertySeparator && i != stackLength - 1)
                {
                    var nextVal = propertyPathExpressionVisitor.Results.Peek();

                    if (nextVal.Length == 1 && nextVal[0] == collectionSeparator)
                    {
                        continue;
                    }
                }

                builder.Append(curValue);
            }
            return(builder.ToString().Trim(propertySeparator, collectionSeparator));
        }
        public static string ToPropertyPath(this Expression expression, char propertySeparator = '.', string collectionSeparator = "[].")
        {
            var propertyPathExpressionVisitor = new PropertyPathExpressionVisitor(propertySeparator.ToString(), collectionSeparator);

            propertyPathExpressionVisitor.Visit(expression);

            var builder = new StringBuilder();

            var stackLength = propertyPathExpressionVisitor.Results.Count;

            for (var i = 0; i < stackLength; i++)
            {
                var curValue = propertyPathExpressionVisitor.Results.Pop();

                if (curValue.Length == 1 && curValue[0] == propertySeparator && i != stackLength - 1)
                {
                    var nextVal = propertyPathExpressionVisitor.Results.Peek();
                    if (nextVal.Length == collectionSeparator.Length && nextVal.Equals(collectionSeparator, StringComparison.OrdinalIgnoreCase))
                    {
                        continue;
                    }
                }

                if (curValue == "$Value" && i != stackLength - 1)
                {
                    // Dictionary[].$Value.PropertyName => Dictionary[].PropertyName
                    continue;
                }

                builder.Append(curValue);
            }

            return(builder.ToString().Trim(propertySeparator, collectionSeparator[0], collectionSeparator[1], collectionSeparator[2]));
        }
		public static string ToPropertyPath(this Expression expression, char propertySeparator = '.', char collectionSeparator = ',')
		{
			var propertyPathExpressionVisitor = new PropertyPathExpressionVisitor(propertySeparator.ToString(CultureInfo.InvariantCulture), collectionSeparator.ToString(CultureInfo.InvariantCulture));
			propertyPathExpressionVisitor.Visit(expression);

			var builder = new StringBuilder();
			foreach (var result in propertyPathExpressionVisitor.Results)
			{
				builder.Append(result);
			}
			return builder.ToString().Trim(propertySeparator, collectionSeparator);
		}
Exemple #4
0
        public static string ToPropertyPath(this Expression expression, char propertySeparator = '.', char collectionSeparator = ',')
        {
            var propertyPathExpressionVisitor = new PropertyPathExpressionVisitor(propertySeparator.ToString(CultureInfo.InvariantCulture), collectionSeparator.ToString(CultureInfo.InvariantCulture));

            propertyPathExpressionVisitor.Visit(expression);

            var builder = new StringBuilder();

            foreach (var result in propertyPathExpressionVisitor.Results)
            {
                builder.Append(result);
            }
            return(builder.ToString().Trim(propertySeparator, collectionSeparator));
        }