CurrentContent attribute and value-resolver #79
Conversation
…ntent currently being mapped)
…shedContent`, and attempt to map it to the target type.
result = ((IPublishedContent)propertyValue).As(propertyInfo.PropertyType); | ||
|
||
// TODO: [LK] Could this be also used to handle IEnumerable<IPublishedContent>? | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to add additional check for IEnumerable< IPublishedContent> where to result type is IEnumerable< Entity> and do ditto cast there too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this as simple as checking for propertyValue is IEnumerable<IPublishedContent>
? or do we have to get funky with all the .IsGenericType
checks?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure, I think might be able to do IsAssignableTo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
propertyValue.IsEnumerableOfType(typeof(IPublishedContent))
Honeymoon is next week 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @JimBobSquarePants!
(See you next week - does it sound weird that we'll see you on your honeymoon?)
Just to clarify, there are two things going on here. The A couple of things that play on my mind are, should the Maybe we have two attributes [CurrentContent]
public IPublishedContent Node { get; set; }
[CurrentContentAs]
public MyModel MyProp { get; set; } The other thing is that I can't decide if the magic |
@@ -545,6 +545,13 @@ public static class PublishedContentExtensions | |||
// Simple types | |||
result = propertyValue; | |||
} | |||
else if (propertyValue is IPublishedContent) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(from Skype) @mattbrailsford suggests that we change to:
else if (propertyValue is IPublishedContent && propertyInfo.PropertyType.IsClass)
making a note here so I don't forget later
Added check on value-resolver to prevent circular-references.
Conflicts: tests/Our.Umbraco.Ditto.Tests/Our.Umbraco.Ditto.Tests.csproj tests/Our.Umbraco.Ditto.Tests/PublishedContentTests.cs
CurrentContent attribute and value-resolver
(Closes #78)
Introduces new attribute and value-resolver to apply the current
IPublishedContent
to a POCO property.An example...
This would be the equivalent of:
foo.MyProperty = content.As<MyOtherModel>()
.