Ejemplo n.º 1
0
        /// <summary>
        /// Retrieve property path info.
        /// Throw error if unavailable.
        /// This only examines public instance properties.
        /// </summary>
        /// <param name="t"></param>
        /// <param name="propertyPathString"></param>
        /// <param name="cacheProvider"></param>
        /// <returns></returns>
        private static IPropertyPath GetPropertyPath(Type t, String propertyPathString, ICacheService cacheProvider)
        {
            String        cacheKey     = null;
            IPropertyPath propertyPath = null;

            if (cacheProvider != null)
            {
                cacheKey     = t.FullName + "#" + propertyPathString;
                propertyPath = cacheProvider[cacheKey] as IPropertyPath;
            }
            if (propertyPath == null)
            {
                if (propertyPathString.IndexOf('.') > -1)
                {
                    propertyPath = new ComplexPropertyPath(t, propertyPathString);
                }
                else
                {
                    propertyPath = new SimplePropertyPath(t, propertyPathString);
                }
                if (cacheProvider != null)
                {
                    cacheProvider[cacheKey] = propertyPath;
                }
            }
            return(propertyPath);
        }
Ejemplo n.º 2
0
        public void TestChildObjectChange()
        {
            bool   sawChange = false;
            FakeVM obj       = new FakeVM {
                Child = new FakeVM {
                    Value = 100
                }
            };
            SimplePropertyPath path = new SimplePropertyPath {
                Root = obj, Path = "Child.Value"
            };

            path.PropertyChanged += (sender, args) => { if (args.PropertyName == "Value")
                                                        {
                                                            sawChange = true;
                                                        }
            };

            Assert.AreEqual(100, path.Value);
            Assert.AreEqual(false, sawChange);

            obj.Child = null;

            Assert.IsNull(path.Value);
            Assert.AreEqual(true, sawChange);

            obj.Child = new FakeVM {
                Value = 113
            };

            Assert.AreEqual(113, path.Value);
        }
Ejemplo n.º 3
0
        public void TestInvalidRead()
        {
            FakeVM obj = new FakeVM {
                Value = 13
            };
            SimplePropertyPath path = new SimplePropertyPath {
                Root = obj, Path = "value"
            };

            Assert.IsNull(path.Value);
        }
Ejemplo n.º 4
0
        public void TestSimpleRead()
        {
            FakeVM obj = new FakeVM {
                Value = 13
            };
            SimplePropertyPath path = new SimplePropertyPath {
                Root = obj, Path = "Value"
            };

            Assert.AreEqual(13, path.Value);
        }
Ejemplo n.º 5
0
        public void TestChildRead()
        {
            FakeVM obj = new FakeVM {
                Child = new FakeVM {
                    Value = 10
                }
            };
            SimplePropertyPath path = new SimplePropertyPath {
                Root = obj, Path = "Child.Value"
            };

            Assert.AreEqual(10, path.Value);
        }
Ejemplo n.º 6
0
        public void TestSimpleWrite()
        {
            FakeVM obj = new FakeVM {
                Value = 13
            };
            SimplePropertyPath path = new SimplePropertyPath {
                Root = obj, Path = "Value"
            };

            path.Value = 17;

            Assert.AreEqual(17, obj.Value);
        }
Ejemplo n.º 7
0
        public void TestInvalidWrite()
        {
            FakeVM obj = new FakeVM {
                Value = 13
            };
            SimplePropertyPath path = new SimplePropertyPath {
                Root = obj, Path = "value"
            };

            path.Value = 17;

            Assert.AreEqual(13, obj.Value);
            Assert.IsNull(path.Value);
        }
Ejemplo n.º 8
0
        public void TestChildWrite()
        {
            FakeVM obj = new FakeVM {
                Child = new FakeVM {
                    Value = 10
                }
            };
            SimplePropertyPath path = new SimplePropertyPath {
                Root = obj, Path = "Child.Value"
            };

            path.Value = 17;

            Assert.AreEqual(17, obj.Child.Value);
        }
Ejemplo n.º 9
0
        public void TestLongChain()
        {
            FakeVM obj = new FakeVM {
                Value = 1
            };
            SimplePropertyPath path = new SimplePropertyPath {
                Root = obj, Path = "Child.Child.Child.Value"
            };

            Assert.IsNull(path.Value);

            obj.Child = new FakeVM {
                Value = 2
            };

            Assert.IsNull(path.Value);

            obj.Child.Child = new FakeVM {
                Value = 3
            };

            Assert.IsNull(path.Value);

            obj.Child.Child.Child = new FakeVM {
                Value = 4
            };

            Assert.AreEqual(4, path.Value);

            obj.Child = new FakeVM {
                Value = 52, Child = new FakeVM {
                    Value = 53, Child = new FakeVM {
                        Value = 54
                    }
                }
            };

            Assert.AreEqual(54, path.Value);
        }
Ejemplo n.º 10
0
        public void TestSimpleChange()
        {
            bool   sawChange = false;
            FakeVM obj       = new FakeVM {
                Value = 11
            };
            SimplePropertyPath path = new SimplePropertyPath {
                Root = obj, Path = "Value"
            };

            path.PropertyChanged += (sender, args) => { if (args.PropertyName == "Value")
                                                        {
                                                            sawChange = true;
                                                        }
            };

            Assert.AreEqual(11, path.Value);
            Assert.AreEqual(false, sawChange);

            obj.Value = 12;

            Assert.AreEqual(12, path.Value);
            Assert.AreEqual(true, sawChange);
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Retrieve property path info.
 /// Throw error if unavailable.
 /// This only examines public instance properties.
 /// </summary>
 /// <param name="t"></param>
 /// <param name="propertyPathString"></param>
 /// <param name="cacheProvider"></param>
 /// <returns></returns>
 private static IPropertyPath GetPropertyPath(Type t, String propertyPathString, ICacheService cacheProvider)
 {
     String cacheKey = null;
     IPropertyPath propertyPath = null;
     if (cacheProvider != null)
     {
         cacheKey = t.FullName + "#" + propertyPathString;
         propertyPath = cacheProvider[cacheKey] as IPropertyPath;
     }
     if (propertyPath == null)
     {
         if (propertyPathString.IndexOf('.') > -1)
         {
             propertyPath = new ComplexPropertyPath(t, propertyPathString);
         }
         else
         {
             propertyPath = new SimplePropertyPath(t, propertyPathString);
         }
         if (cacheProvider != null)
         {
             cacheProvider[cacheKey] = propertyPath;
         }
     }
     return propertyPath;
 }