Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Allow null values to be passed in via the anonymous object

Handles when you pass a null value into Plant via the optional
properties. For example:

    plant.Create<Person>(new {
      Address = (Address)null
    });

For situations where the property needs to be null, but defaults to
something in the class.
  • Loading branch information...
commit 8248e3621fbb5ebfee2daa75c9d3e379088877e4 1 parent f6d6cdf
@jagregory authored
Showing with 10 additions and 0 deletions.
  1. +2 −0  Plant.Core/BasePlant.cs
  2. +8 −0 Plant.Tests/BasePlantTest.cs
View
2  Plant.Core/BasePlant.cs
@@ -88,6 +88,8 @@ private void SetProperties<T>(Properties properties, T instance)
if (instanceProperty == null) throw new PropertyNotFoundException(property.Name, properties[property]);
var value = properties[property];
+ if (value == null)
+ return;
if (typeof(ILazyProperty).IsAssignableFrom(value.GetType()))
AssignLazyPropertyResult(instance, instanceProperty, value);
else if(typeof(ISequence).IsAssignableFrom(value.GetType()))
View
8 Plant.Tests/BasePlantTest.cs
@@ -36,6 +36,14 @@ public void Should_Use_Default_Instance_Values()
}
[Test]
+ public void Should_Create_Instance_With_Null_Value()
+ {
+ var testPlant = new BasePlant();
+ testPlant.DefinePropertiesOf<Person>(new { FirstName = "Barbara", LastName = (string)null });
+ Assert.IsNull(testPlant.Create<Person>().LastName);
+ }
+
+ [Test]
[ExpectedException(typeof(PropertyNotFoundException))]
public void Should_Throw_PropertyNotFound_Exception_When_Given_Invalid_Property()
{
Please sign in to comment.
Something went wrong with that request. Please try again.