CreatePathSegment() public method

public CreatePathSegment ( PropertyInfo property ) : IPathSegment
property System.Reflection.PropertyInfo
return IPathSegment
コード例 #1
0
        private IPath BuildPath(Stack <Tuple <PropertyInfo, bool, object> > propertyStack, PropertyInfo property,
                                object root)
        {
            var path = new PocoPath();

            path.ActualPath = string.Join(PocoPath.SeperatorSymbol,
                                          propertyStack.Reverse().Select(p => path.CreatePathSegment(p.Item1).ToString(p.Item2)));

            List <Tuple <IPathSegment, bool> > displayPathSegments =
                propertyStack.Reverse()
                .Select(p => new Tuple <IPathSegment, bool>(path.CreatePathSegment(p.Item1), p.Item2))
                .ToList();
            bool recordsetEncountered = false;

            for (int i = displayPathSegments.Count - 1; i >= 0; i--)
            {
                Tuple <IPathSegment, bool> pathSegment = displayPathSegments[i];
                if (recordsetEncountered)
                {
                    pathSegment.Item1.IsEnumarable = false;
                }

                if (pathSegment.Item1.IsEnumarable && pathSegment.Item2)
                {
                    recordsetEncountered = true;
                }
            }

            path.DisplayPath = string.Join(PocoPath.SeperatorSymbol,
                                           displayPathSegments.Select(p => p.Item1.ToString(p.Item2)));

            if (path.ActualPath != string.Empty)
            {
                path.ActualPath += PocoPath.SeperatorSymbol;
            }

            if (path.DisplayPath != string.Empty)
            {
                path.DisplayPath += PocoPath.SeperatorSymbol;
            }

            path.ActualPath  += path.CreatePathSegment(property).ToString();
            path.DisplayPath += path.CreatePathSegment(property).ToString();
            path.SampleData   = GetSampleData(root, path);

            return(path);
        }
コード例 #2
0
ファイル: PocoMapper.cs プロジェクト: kapiya/Warewolf
        IPath BuildPath(Stack <Tuple <string, bool, bool, object> > propertyStack, string name, bool isEnumerable)
        {
            var path = new PocoPath();

            path.ActualPath = string.Join(PocoPath.SeperatorSymbol,
                                          propertyStack.Reverse().Select(p => path.CreatePathSegment(p.Item1, p.Item2).ToString(p.Item3)));

            var displayPathSegments =
                propertyStack.Reverse()
                .Select(p => new Tuple <IPathSegment, bool>(path.CreatePathSegment(p.Item1, p.Item2), p.Item3))
                .ToList();
            var recordsetEncountered = false;

            for (int i = displayPathSegments.Count - 1; i >= 0; i--)
            {
                var pathSegment = displayPathSegments[i];
                if (recordsetEncountered)
                {
                    pathSegment.Item1.IsEnumarable = false;
                }

                if (pathSegment.Item1.IsEnumarable && pathSegment.Item2)
                {
                    recordsetEncountered = true;
                }
            }

            path.DisplayPath = string.Join(PocoPath.SeperatorSymbol,
                                           displayPathSegments.Select(p => p.Item1.ToString(p.Item2)));

            if (path.ActualPath != string.Empty)
            {
                path.ActualPath += PocoPath.SeperatorSymbol;
            }

            if (path.DisplayPath != string.Empty)
            {
                path.DisplayPath += PocoPath.SeperatorSymbol;
            }

            path.ActualPath  += path.CreatePathSegment(name, isEnumerable);
            path.DisplayPath += path.CreatePathSegment(name, isEnumerable);

            return(path);
        }
コード例 #3
0
        public void ToStringOnEnumerableSegment_WhereEnumerablesAreConsidered_Expected_ScalarFormat()
        {
            PocoPath path = new PocoPath();
            IPathSegment segment = path.CreatePathSegment("Collection()");

            const string expected = "Collection()";
            string actual = segment.ToString(true);

            Assert.AreEqual(expected, actual);
        }
コード例 #4
0
        public void ToStringOnScalarSegment_Expected_ScalarFormat()
        {
            PocoPath path = new PocoPath();
            IPathSegment segment = path.CreatePathSegment("Name");

            const string expected = "Name";
            string actual = segment.ToString();

            Assert.AreEqual(expected, actual);
        }
コード例 #5
0
        public void CreateScalarPathSegmentFromPropertyInfo_Expected_ScalarPocoPathSegment()
        {
            PropertyInfo propertyInfo = typeof(PocoTestData).GetProperty("Name");
            PocoPath path = new PocoPath();
            IPathSegment segment = path.CreatePathSegment(propertyInfo);

            bool expected = false;
            bool actual = segment.IsEnumarable;

            Assert.AreEqual(expected, actual);
        }
コード例 #6
0
        public void CreateEnumerablePathSegmentFromPropertyInfo_Expected_EnumerablePocoPathSegment()
        {
            PropertyInfo propertyInfo = typeof(PocoTestData).GetProperty("EnumerableData");
            PocoPath path = new PocoPath();
            IPathSegment segment = path.CreatePathSegment(propertyInfo);

            const bool expected = true;
            bool actual = segment.IsEnumarable;

            Assert.AreEqual(expected, actual);
        }
コード例 #7
0
        public void CreateEnumerablePathSegmentFromSegmentText_Expected_EnumerablePocoPathSegment()
        {
            PocoPath path = new PocoPath();
            IPathSegment segment = path.CreatePathSegment("EnumerableData()");

            bool expected = true;
            bool actual = segment.IsEnumarable;

            Assert.AreEqual(expected, actual);
        }
コード例 #8
0
        public void CreateScalarPathSegmentFromSegmentText_Expected_ScalarPocoPathSegment()
        {
            PocoPath path = new PocoPath();
            IPathSegment segment = path.CreatePathSegment("Name");

            bool expected = false;
            bool actual = segment.IsEnumarable;

            Assert.AreEqual(expected, actual);
        }
コード例 #9
0
        private IPath BuildPath(Stack<Tuple<PropertyInfo, bool, object>> propertyStack, PropertyInfo property,
            object root)
        {
            var path = new PocoPath();

            path.ActualPath = string.Join(PocoPath.SeperatorSymbol,
                propertyStack.Reverse().Select(p => path.CreatePathSegment(p.Item1).ToString(p.Item2)));

            List<Tuple<IPathSegment, bool>> displayPathSegments =
                propertyStack.Reverse()
                    .Select(p => new Tuple<IPathSegment, bool>(path.CreatePathSegment(p.Item1), p.Item2))
                    .ToList();
            bool recordsetEncountered = false;

            for (int i = displayPathSegments.Count - 1; i >= 0; i--)
            {
                Tuple<IPathSegment, bool> pathSegment = displayPathSegments[i];
                if (recordsetEncountered)
                {
                    pathSegment.Item1.IsEnumarable = false;
                }

                if (pathSegment.Item1.IsEnumarable && pathSegment.Item2) recordsetEncountered = true;
            }

            path.DisplayPath = string.Join(PocoPath.SeperatorSymbol,
                displayPathSegments.Select(p => p.Item1.ToString(p.Item2)));

            if (path.ActualPath != string.Empty)
            {
                path.ActualPath += PocoPath.SeperatorSymbol;
            }

            if (path.DisplayPath != string.Empty)
            {
                path.DisplayPath += PocoPath.SeperatorSymbol;
            }

            path.ActualPath += path.CreatePathSegment(property).ToString();
            path.DisplayPath += path.CreatePathSegment(property).ToString();
            path.SampleData = GetSampleData(root, path);

            return path;
        }