DependencyProperty of DependencyObject was trowing KeyNotFound exception instead...
authorDavid Karlaš <david.karlas@gmail.com>
Fri, 24 May 2013 18:53:17 +0000 (20:53 +0200)
committerDavid Karlaš <david.karlas@gmail.com>
Fri, 24 May 2013 18:53:17 +0000 (20:53 +0200)
mcs/class/WindowsBase/System.Windows/DependencyObject.cs
mcs/class/WindowsBase/Test/System.Windows/DependencyObjectTest.cs

index 943e2407da7dcb23b7656abe1e08f0d6338cdf43..d9de2772a17c54966073d64dc35a1933137b08df 100644 (file)
@@ -83,7 +83,7 @@ namespace System.Windows {
                
                public object GetValue(DependencyProperty dp)
                {
-                       object val = properties[dp];
+                       object val = properties.ContainsKey (dp) ? properties [dp] : null;
                        return val == null ? dp.DefaultMetadata.DefaultValue : val;
                }
                
@@ -102,7 +102,7 @@ namespace System.Windows {
                
                public object ReadLocalValue(DependencyProperty dp)
                {
-                       object val = properties[dp];
+                       object val = properties.ContainsKey (dp) ? properties [dp] : null;
                        return val == null ? DependencyProperty.UnsetValue : val;
                }
                
index 31bdad96fcc0e149a51f9e4efa055f4d1a204969..2700953a8b275e9acbb43c8ec197c9df9fcad8e9 100644 (file)
@@ -59,6 +59,10 @@ namespace MonoTests.System.Windows {
        class Y : DependencyObject {
        }
 
+       class DefaultValueTest : DependencyObject {
+               public static readonly DependencyProperty AProperty = DependencyProperty.Register("A", typeof(string), typeof(DefaultValueTest), new PropertyMetadata("defaultValueTest"));
+       }
+
        [TestFixture]
        public class DependencyObjectTest {
                [Test]
@@ -105,5 +109,12 @@ namespace MonoTests.System.Windows {
                        Assert.AreEqual(2, count);
                }
 
+               [Test]
+               public void TestDefaultValue()
+               {
+                       DefaultValueTest obj = new DefaultValueTest ();
+                       Assert.AreEqual (obj.GetValue(DefaultValueTest.AProperty), "defaultValueTest");
+               }
+
        }
 }