diff options
author | Stephane Delcroix <stephane@delcroix.org> | 2017-02-02 11:14:35 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-02 11:14:35 +0100 |
commit | c25a360efbbbe1f161e6737e61aed4b96cd37ac3 (patch) | |
tree | bf8dac966d5b5c5d3851ed507e729547efff9df9 /Xamarin.Forms.Xaml | |
parent | fa0882114d31387acaa8d6f43b638a0bf1efa871 (diff) | |
download | xamarin-forms-c25a360efbbbe1f161e6737e61aed4b96cd37ac3.tar.gz xamarin-forms-c25a360efbbbe1f161e6737e61aed4b96cd37ac3.tar.bz2 xamarin-forms-c25a360efbbbe1f161e6737e61aed4b96cd37ac3.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.cs | 5 |
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]; |