Beispiel #1
0
        public static PropertyPath <TValue> Create <TValue>(Expression <Func <TValue> > propertyExpression)
        {
            var          path          = PropertyPathVisitor.GetPath(propertyExpression);
            var          propertyInfos = path.Cast <PropertyInfo>().ToArray();
            var          parts         = new PathProperty[propertyInfos.Length];
            PathProperty previous      = null;

            for (int i = 0; i < propertyInfos.Length; i++)
            {
                var propertyInfo = propertyInfos[i];
                var item         = new PathProperty(previous, propertyInfo);
                parts[i] = item;
                previous = item;
            }

            var constants = ConstantVisitor.GetConstants(propertyExpression);

            if (!constants.Any())
            {
                throw new ArgumentException("Expression contains no constants", nameof(propertyExpression));
            }

            //valuePath.Source = source;
            var source       = constants.Last().Value;
            var propertyPath = new PropertyPath(parts);

            return(new PropertyPath <TValue>(propertyPath, source));
        }
Beispiel #2
0
        public static PropertyPath <TSource, TValue> Create <TSource, TValue>(Expression <Func <TSource, TValue> > propertyExpression)
        {
            var          path          = PropertyPathVisitor.GetPath(propertyExpression);
            var          propertyInfos = path.Cast <PropertyInfo>().ToArray();
            var          parts         = new PathProperty[propertyInfos.Length];
            PathProperty previous      = null;

            for (int i = 0; i < propertyInfos.Length; i++)
            {
                var propertyInfo = propertyInfos[i];
                var item         = new PathProperty(previous, propertyInfo);
                parts[i] = item;
                previous = item;
            }

            return(new PropertyPath <TSource, TValue>(new PropertyPath(parts)));
        }