summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Xaml
diff options
context:
space:
mode:
authorStephane Delcroix <stephane@delcroix.org>2017-02-02 14:28:59 (GMT)
committerGitHub <noreply@github.com>2017-02-02 14:28:59 (GMT)
commit750b0346ccd5e06fc6ae7a7edaac9d745d8e1e65 (patch)
tree089ffffbbb96df8dbd04318f58924ce941169c3d /Xamarin.Forms.Xaml
parenteacbc1acf4cc2b95b98099d069e7bfa31c89f4f8 (diff)
downloadxamarin-forms-750b0346ccd5e06fc6ae7a7edaac9d745d8e1e65.zip
xamarin-forms-750b0346ccd5e06fc6ae7a7edaac9d745d8e1e65.tar.gz
xamarin-forms-750b0346ccd5e06fc6ae7a7edaac9d745d8e1e65.tar.bz2
[Xaml] do not set properties with private setters (#717)
Diffstat (limited to 'Xamarin.Forms.Xaml')
-rw-r--r--Xamarin.Forms.Xaml/ApplyPropertiesVisitor.cs20
1 files changed, 18 insertions, 2 deletions
diff --git a/Xamarin.Forms.Xaml/ApplyPropertiesVisitor.cs b/Xamarin.Forms.Xaml/ApplyPropertiesVisitor.cs
index 3ea1d1c..833d5d9 100644
--- a/Xamarin.Forms.Xaml/ApplyPropertiesVisitor.cs
+++ b/Xamarin.Forms.Xaml/ApplyPropertiesVisitor.cs
@@ -297,7 +297,7 @@ namespace Xamarin.Forms.Xaml
return;
//If we can assign that value to a normal property, let's do it
- if (xpe == null && TrySetProperty(xamlelement, localName, value, lineInfo, serviceProvider, out xpe))
+ if (xpe == null && TrySetProperty(xamlelement, localName, value, lineInfo, serviceProvider, context, out xpe))
return;
//If it's an already initialized property, add to it
@@ -423,7 +423,7 @@ namespace Xamarin.Forms.Xaml
return false;
}
- static bool TrySetProperty(object element, string localName, object value, IXmlLineInfo lineInfo, XamlServiceProvider serviceProvider, out Exception exception)
+ static bool TrySetProperty(object element, string localName, object value, IXmlLineInfo lineInfo, XamlServiceProvider serviceProvider, HydratationContext context, out Exception exception)
{
exception = null;
@@ -433,6 +433,9 @@ namespace Xamarin.Forms.Xaml
if (propertyInfo == null || !propertyInfo.CanWrite || (setter = propertyInfo.SetMethod) == null)
return false;
+ if (!IsVisibleFrom(setter, context.RootElement))
+ return false;
+
object convertedValue = value.ConvertTo(propertyInfo.PropertyType, () => propertyInfo, serviceProvider);
if (convertedValue != null && !propertyInfo.PropertyType.IsInstanceOfType(convertedValue))
return false;
@@ -441,6 +444,19 @@ namespace Xamarin.Forms.Xaml
return true;
}
+ static bool IsVisibleFrom(MethodInfo setter, object rootElement)
+ {
+ if (setter.IsPublic)
+ return true;
+ if (setter.IsPrivate && setter.DeclaringType == rootElement.GetType())
+ return true;
+ if ((setter.IsAssembly || setter.IsFamilyOrAssembly) && setter.DeclaringType.AssemblyQualifiedName == rootElement.GetType().AssemblyQualifiedName)
+ return true;
+ if (setter.IsFamily && setter.DeclaringType.IsAssignableFrom(rootElement.GetType()))
+ return true;
+ return false;
+ }
+
static bool TryAddToProperty(object element, string localName, object value, IXmlLineInfo lineInfo, XamlServiceProvider serviceProvider, out Exception exception)
{
exception = null;