summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Xaml/ApplyPropertiesVisitor.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Xamarin.Forms.Xaml/ApplyPropertiesVisitor.cs')
-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 3ea1d1c5..833d5d94 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;