public void an_instance_part_of_the_path_is_replaced_with_the_prefix_in_object_paths()
        {
            try
            {
                ObjectPaths.Add(Customer, new PropertyPath {
                    TypePrefix = "Customer", TypeSuffix = "TheFirst"
                });

                var pp = new PropertyPathForInstance <object>(() => Customer.FirstName);
                pp.Path.TypePrefix.ShouldBe("Customer");
                pp.Path.TypeSuffix.ShouldBe("TheFirst.FirstName");
            }
            finally
            {
                ObjectPaths.Remove(Customer);
            }
        }
Exemplo n.º 2
0
        public static IEnumerable <TResult> SelectHtml <TSource, TResult>(this IEnumerable <TSource> source,
                                                                          object rootInstance,
                                                                          PropertyPath path,
                                                                          Func <TSource, TResult> selector)
        {
            if (source == null)
            {
                yield break;
            }
            int index = 0;

            foreach (var item in source)
            {
                try
                {
                    PropertyPath pathToAdd;
                    if (rootInstance != null)
                    {
                        PropertyPath rootPath = ObjectPaths.Get(rootInstance);
                        pathToAdd = new PropertyPath
                        {
                            TypePrefix = rootPath.TypePrefix,
                            TypeSuffix = rootPath.TypeSuffix + "." + path.TypeSuffix + ":" + index
                        };
                    }
                    else
                    {
                        pathToAdd = new PropertyPath
                        {
                            TypePrefix = path.TypePrefix,
                            TypeSuffix = path.TypeSuffix + ":" + index
                        };
                    }
                    ObjectPaths.Add(item, pathToAdd);
                    yield return(selector(item));
                }
                finally
                {
                    ObjectPaths.Remove(item);
                    index++;
                }
            }
        }