summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Xaml
diff options
context:
space:
mode:
authorStephane Delcroix <stephane@delcroix.org>2017-02-02 11:14:35 +0100
committerKangho Hur <kangho.hur@samsung.com>2017-03-24 13:18:32 +0900
commitfc482ef2eb128dae25342613a3e6d6d0f676419a (patch)
treee39be7f3b0728573a9e791f04571728a8ec8d186 /Xamarin.Forms.Xaml
parentd76030e441b0b64aa6aaaea7cdaab243161da535 (diff)
downloadxamarin-forms-fc482ef2eb128dae25342613a3e6d6d0f676419a.tar.gz
xamarin-forms-fc482ef2eb128dae25342613a3e6d6d0f676419a.tar.bz2
xamarin-forms-fc482ef2eb128dae25342613a3e6d6d0f676419a.zip
[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 47ef9f6c..3ea1d1c5 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];