/// <summary>
        /// Parse the property name and initialize necessary extractor and
        /// updater.
        /// </summary>
        protected internal void Init()
        {
            // allow composite property name (not documented)
            string name   = m_name;
            int    ofLast = name.LastIndexOf('.');
            string prop   = name.Substring(ofLast + 1);

            IValueExtractor extractor = new ReflectionExtractor(prop); //(m_useIs ? "is" : "get") +
            IValueUpdater   updater   = new ReflectionUpdater(prop); //"set" +

            if (ofLast > 0)
            {
                string[] array = name.Substring(0, ofLast).Split(new char[] {'.'});
                int      count = array.Length;

                IValueExtractor[] veGet = new IValueExtractor[count + 1];
                IValueExtractor[] vePut = new IValueExtractor[count];
                for (int i = 0; i < count; i++)
                {
                    veGet[i] = vePut[i] = new ReflectionExtractor(array[i]); //"get" +
                }
                veGet[count] = extractor;

                extractor = new ChainedExtractor(veGet);
                updater   = new CompositeUpdater(count == 1 ? vePut[0] : new ChainedExtractor(vePut),
                                                 updater);

            }
            m_extractor = extractor;
            m_updater   = updater;
        }
Exemplo n.º 2
0
        public void TestComparer()
        {
            INamedCache cache = CacheFactory.GetCache("dist-comparator-cache");
            Random      r     = new Random();

            for (int i = 0; i < 10000; i++)
            {
                AirDealComparer.AirDeal deal = new AirDealComparer.AirDeal(i, "SFO", "JFK", r.NextDouble());
                cache.Add(deal.Oid, deal);
            }
            IValueExtractor ve = new ReflectionExtractor("getOrigAirport");

            cache.AddIndex(ve, true, null);

            IFilter     primaryFilter = new EqualsFilter(ve, "SFO");
            IFilter     filterLimit   = new LimitFilter(primaryFilter, 40);
            ICollection setReturn     = cache.GetEntries(filterLimit, new AirDealComparer());

            Assert.AreEqual(setReturn.Count, 40);
        }