Пример #1
0
        public Expression GetAccessor(Expression source)
        {
            var result = source;

            if (!string.IsNullOrEmpty(Path))
            {
                var dps      = new Stack <DependencyPropertyPos>();
                var property = new PropertyPos();
                var dpp      = new DependencyPropertyPos();

                int index = 0;
                if (Path[0] != '{')
                {
                    property.Start = 0;
                }
                foreach (var c in Path)
                {
                    if (c == '{')
                    {
                        dpp.BracketStart = index;
                    }
                    else if (c == '}')
                    {
                        dpp.BracketEnd = index;
                    }
                    else if (c == '.')
                    {
                        if (dpp.BracketEnd != null)
                        {
                            result = BuildExpression(result, ref dpp);
                        }
                        else
                        {
                            if (property.Start == null)
                            {
                                property.Start = index + 1;
                            }
                            else
                            {
                                property.End = index - 1;

                                result = BuildExpression(result, ref property);
                            }
                        }
                    }
                    index++;
                }

                if (property.Start != null)
                {
                    property.End = index - 1;
                    result       = BuildExpression(result, ref property);
                }
                else if (dpp.BracketEnd != null)
                {
                    result = BuildExpression(result, ref dpp);
                }
            }
            return(Expression.Convert(result, typeof(object)));
        }
Пример #2
0
 private Expression BuildExpression(Expression result, ref PropertyPos property)
 {
     result       = Expression.Property(result, Path.Substring(property.Start.Value, (property.End - property.Start).Value + 1));
     property.End = property.Start = null;
     return(result);
 }