Permalink
Browse files

Fix crash when checking validity of a ReactiveValidatedObject which h…

…as public static properties

ReactiveUI.PropertyExtraInfo.CreateFromType was finding all public
properties, then attempting to treat them all as instance properties in
CreateFromTypeAndName. It now filters its GetProperties call to public
instance properties only.

This commit also add a test which fails without the change to
Validation.cs.
  • Loading branch information...
1 parent d9c9f90 commit 2f4fac2188451c6e8a18811a24e2f9a519d31345 Matthew Walton committed Feb 15, 2013
Showing with 25 additions and 1 deletion.
  1. +24 −0 ReactiveUI.Tests/ReactiveValidatedObjectTest.cs
  2. +1 −1 ReactiveUI/Validation.cs
@@ -31,6 +31,19 @@ public class ValidatedTestFixture : ReactiveValidatedObject
}
}
+ public class ValidatedIgnoresStaticPropertyTestFixture : ReactiveValidatedObject
+ {
+ public static int StaticProperty
+ {
+ get { return 5; }
+ }
+
+ public string NonStaticProperty
+ {
+ get { return "A string"; }
+ }
+ }
+
public class ReactiveValidatedObjectTest
{
[Fact]
@@ -60,5 +73,16 @@ public void IsObjectValidTest()
.ForEach(x => Assert.Equal(x.expected, x.actual));
*/
}
+
+ [Fact]
+ public void IgnoresStaticPropertiesTest()
+ {
+ var fixture = new ValidatedIgnoresStaticPropertyTestFixture();
+
+ Assert.DoesNotThrow(delegate
+ {
+ var error = fixture["NonStaticProperty"];
+ });
+ }
}
}
View
@@ -175,7 +175,7 @@ public static PropertyExtraInfo CreateFromTypeAndName(Type type, string property
public static PropertyExtraInfo[] CreateFromType(Type type)
{
- return type.GetProperties()
+ return type.GetProperties(BindingFlags.Instance | BindingFlags.Public)
.Select(x => CreateFromTypeAndName(type, x.Name, true))
.Where(x => x != null)
.ToArray();

0 comments on commit 2f4fac2

Please sign in to comment.