Skip to content

Commit

Permalink
Merge pull request #648 from DavidKarlas/defaultDependcyObject
Browse files Browse the repository at this point in the history
DependencyObject default value
  • Loading branch information
marek-safar committed May 25, 2013
2 parents 54d8ffe + 91d3a70 commit a53f8f5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions mcs/class/WindowsBase/System.Windows/DependencyObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public LocalValueEnumerator GetLocalValueEnumerator()

public object GetValue(DependencyProperty dp)
{
object val = properties[dp];
object val = properties.ContainsKey (dp) ? properties [dp] : null;
return val == null ? dp.DefaultMetadata.DefaultValue : val;
}

Expand All @@ -102,7 +102,7 @@ protected virtual void OnPropertyChanged(DependencyPropertyChangedEventArgs e)

public object ReadLocalValue(DependencyProperty dp)
{
object val = properties[dp];
object val = properties.ContainsKey (dp) ? properties [dp] : null;
return val == null ? DependencyProperty.UnsetValue : val;
}

Expand Down
11 changes: 11 additions & 0 deletions mcs/class/WindowsBase/Test/System.Windows/DependencyObjectTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ public static string GetB(DependencyObject obj)
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]
Expand Down Expand Up @@ -105,5 +109,12 @@ public void TestEnumerationOfAttachedProperties()
Assert.AreEqual(2, count);
}

[Test]
public void TestDefaultValue()
{
DefaultValueTest obj = new DefaultValueTest ();
Assert.AreEqual (obj.GetValue(DefaultValueTest.AProperty), "defaultValueTest");
}

}
}

0 comments on commit a53f8f5

Please sign in to comment.