summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Xaml
diff options
context:
space:
mode:
authorStephane Delcroix <stephane@delcroix.org>2017-02-02 10:14:35 (GMT)
committerGitHub <noreply@github.com>2017-02-02 10:14:35 (GMT)
commitc25a360efbbbe1f161e6737e61aed4b96cd37ac3 (patch)
treebf8dac966d5b5c5d3851ed507e729547efff9df9 /Xamarin.Forms.Xaml
parentfa0882114d31387acaa8d6f43b638a0bf1efa871 (diff)
downloadxamarin-forms-c25a360efbbbe1f161e6737e61aed4b96cd37ac3.zip
xamarin-forms-c25a360efbbbe1f161e6737e61aed4b96cd37ac3.tar.gz
xamarin-forms-c25a360efbbbe1f161e6737e61aed4b96cd37ac3.tar.bz2
[Xaml[C]] throw meaningful exception while trying to set the content … (#714)
* [Xaml[C]] throw meaningful exception while trying to set the content of a property without ContentPropertyAttribute * fix test
Diffstat (limited to 'Xamarin.Forms.Xaml')
-rw-r--r--Xamarin.Forms.Xaml/ApplyPropertiesVisitor.cs5
1 files changed, 3 insertions, 2 deletions
diff --git a/Xamarin.Forms.Xaml/ApplyPropertiesVisitor.cs b/Xamarin.Forms.Xaml/ApplyPropertiesVisitor.cs
index 47ef9f6..3ea1d1c 100644
--- a/Xamarin.Forms.Xaml/ApplyPropertiesVisitor.cs
+++ b/Xamarin.Forms.Xaml/ApplyPropertiesVisitor.cs
@@ -121,7 +121,7 @@ namespace Xamarin.Forms.Xaml
} else if (IsCollectionItem(node, parentNode) && parentNode is IElementNode) {
// Collection element, implicit content, or implicit collection element.
string contentProperty;
- if (typeof(IEnumerable).GetTypeInfo().IsAssignableFrom(Context.Types [parentElement].GetTypeInfo())) {
+ if (typeof(IEnumerable).GetTypeInfo().IsAssignableFrom(Context.Types [parentElement].GetTypeInfo()) && Context.Types[parentElement].GetRuntimeMethods().Any(mi => mi.Name == "Add" && mi.GetParameters().Length == 1)) {
var source = Values [parentNode];
if (!(typeof(ResourceDictionary).IsAssignableFrom(Context.Types [parentElement]))) {
var addMethod =
@@ -137,7 +137,8 @@ namespace Xamarin.Forms.Xaml
var source = Values [parentNode];
SetPropertyValue(source, name, value, Context.RootElement, node, Context, node);
- }
+ } else
+ throw new XamlParseException($"Can not set the content of {((IElementNode)parentNode).XmlType.Name} as it doesn't have a ContentPropertyAttribute", node);
} else if (IsCollectionItem(node, parentNode) && parentNode is ListNode) {
var parentList = (ListNode)parentNode;
var source = Values [parentNode.Parent];