Browse Source

portable.xaml parses well avalonia properties without getters/setters

pull/916/head
Andrey Kunchev 10 years ago
parent
commit
55d1bf10d2
  1. 9
      src/Markup/Avalonia.Markup.Xaml/PortableXaml/AvaloniaXamlSchemaContext.cs
  2. 120
      src/Markup/Avalonia.Markup.Xaml/PortableXaml/AvaloniaXamlType.cs

9
src/Markup/Avalonia.Markup.Xaml/PortableXaml/AvaloniaXamlSchemaContext.cs

@ -157,11 +157,10 @@ namespace Avalonia.Markup.Xaml.PortableXaml
return BindingXamlType.Create(type, this); return BindingXamlType.Create(type, this);
} }
//TODO: do we need it ??? if (typeof(AvaloniaObject).GetTypeInfo().IsAssignableFrom(type.GetTypeInfo()))
//if (type.FullName.StartsWith("Avalonia.")) {
//{ return new AvaloniaXamlType(type, this);
// return new AvaloniaXamlType(type, this); }
//}
return null; return null;
} }

120
src/Markup/Avalonia.Markup.Xaml/PortableXaml/AvaloniaXamlType.cs

@ -21,26 +21,47 @@ namespace Avalonia.Markup.Xaml.PortableXaml
base(underlyingType, schemaContext) base(underlyingType, schemaContext)
{ {
} }
protected override XamlMember LookupMember(string name, bool skipReadOnlyCheck)
{
var m = base.LookupMember(name, skipReadOnlyCheck);
if (m == null)
{
//so far Portable.xaml haven't found the member/property
//but what if we have AvaloniaProperty
//without setter and/or without getter
//let's try to find the AvaloniaProperty as a fallback
var avProp = AvaloniaPropertyRegistry.Instance.FindRegistered(UnderlyingType, name);
if (avProp != null && !(skipReadOnlyCheck && avProp.IsReadOnly))
{
m = new AvaloniaPropertyXamlMember(avProp, this);
}
}
return m;
}
} }
public class BindingXamlType : AvaloniaXamlType public class BindingXamlType : XamlType
{ {
public static BindingXamlType Create(Type type, XamlSchemaContext schemaContext) public static BindingXamlType Create(Type type, XamlSchemaContext schemaContext)
{ {
if (type == typeof(Binding)) if (type == typeof(Binding))
{ {
//in xmal we need to use the extension //in xaml we need to use the extension
type = typeof(BindingExtension); type = typeof(BindingExtension);
} }
return new BindingXamlType(type, schemaContext); return new BindingXamlType(type, schemaContext);
} }
private static HashSet<Type> _notAssignable = private static List<Type> _notAssignable =
new HashSet<Type>() new List<Type>
{ {
typeof (IXmlSerializable) typeof (IXmlSerializable)
}; };
private BindingXamlType(Type underlyingType, XamlSchemaContext schemaContext) : private BindingXamlType(Type underlyingType, XamlSchemaContext schemaContext) :
base(underlyingType, schemaContext) base(underlyingType, schemaContext)
@ -49,37 +70,25 @@ namespace Avalonia.Markup.Xaml.PortableXaml
public override bool CanAssignTo(XamlType xamlType) public override bool CanAssignTo(XamlType xamlType)
{ {
if (_notAssignable.Contains(xamlType.UnderlyingType)) return !_notAssignable.Contains(xamlType.UnderlyingType);
{
return false;
}
return true;
}
protected override XamlMember LookupAliasedProperty(XamlDirective directive)
{
return base.LookupAliasedProperty(directive);
}
protected override bool LookupIsMarkupExtension()
{
return base.LookupIsMarkupExtension();
} }
} }
public class PropertyXamlMember : XamlMember public class PropertyXamlMember : XamlMember
{ {
public PropertyXamlMember(PropertyInfo propertyInfo, XamlSchemaContext schemaContext)
: base(propertyInfo, schemaContext)
{
}
protected PropertyXamlMember(string attachablePropertyName, protected PropertyXamlMember(string attachablePropertyName,
MethodInfo getter, MethodInfo setter, XamlSchemaContext schemaContext) MethodInfo getter, MethodInfo setter, XamlSchemaContext schemaContext)
: base(attachablePropertyName, getter, setter, schemaContext) : base(attachablePropertyName, getter, setter, schemaContext)
{ {
} }
public PropertyXamlMember( protected PropertyXamlMember(string name, XamlType declaringType, bool isAttachable)
PropertyInfo propertyInfo, : base(name, declaringType, isAttachable)
XamlSchemaContext schemaContext) :
base(propertyInfo, schemaContext)
{ {
} }
@ -122,19 +131,29 @@ namespace Avalonia.Markup.Xaml.PortableXaml
protected override XamlType LookupType() protected override XamlType LookupType()
{ {
var pi = UnderlyingMember as PropertyInfo; var propType = GetPropertyType();
if (pi != null)
if (propType != null)
{ {
if (pi.PropertyType == typeof(IEnumerable)) if (propType == typeof(IEnumerable))
{ {
//TODO: Portable.xaml is not handling well IEnumerable
//let's threat IEnumerable property as list //let's threat IEnumerable property as list
return DeclaringType.SchemaContext.GetXamlType(typeof(IList)); //revisit this when smarter solution is found
propType = typeof(IList);
} }
return DeclaringType.SchemaContext.GetXamlType(propType);
} }
return base.LookupType(); return base.LookupType();
} }
protected virtual Type GetPropertyType()
{
return (UnderlyingMember as PropertyInfo)?.PropertyType;
}
private IList<XamlMember> _dependsOn; private IList<XamlMember> _dependsOn;
protected override IList<XamlMember> LookupDependsOn() protected override IList<XamlMember> LookupDependsOn()
@ -246,18 +265,10 @@ namespace Avalonia.Markup.Xaml.PortableXaml
{ {
private bool? _assignBinding; private bool? _assignBinding;
public bool AssignBinding => (bool)(_assignBinding ?? (_assignBinding = UnderlyingMember.GetCustomAttribute<AssignBindingAttribute>() != null)); public bool AssignBinding => (bool)(_assignBinding ?? (_assignBinding = UnderlyingMember?.GetCustomAttribute<AssignBindingAttribute>() != null));
public AvaloniaProperty Property { get; } public AvaloniaProperty Property { get; }
protected AvaloniaPropertyXamlMember(AvaloniaProperty property,
string attachablePropertyName,
MethodInfo getter, MethodInfo setter, XamlSchemaContext schemaContext)
: base(attachablePropertyName, getter, setter, schemaContext)
{
Property = property;
}
public AvaloniaPropertyXamlMember(AvaloniaProperty property, public AvaloniaPropertyXamlMember(AvaloniaProperty property,
PropertyInfo propertyInfo, PropertyInfo propertyInfo,
XamlSchemaContext schemaContext) : XamlSchemaContext schemaContext) :
@ -266,6 +277,20 @@ namespace Avalonia.Markup.Xaml.PortableXaml
Property = property; Property = property;
} }
public AvaloniaPropertyXamlMember(AvaloniaProperty property, XamlType type) :
base(property.Name, type, false)
{
Property = property;
}
protected AvaloniaPropertyXamlMember(AvaloniaProperty property,
string attachablePropertyName,
MethodInfo getter, MethodInfo setter, XamlSchemaContext schemaContext)
: base(attachablePropertyName, getter, setter, schemaContext)
{
Property = property;
}
protected override XamlMemberInvoker LookupInvoker() protected override XamlMemberInvoker LookupInvoker()
{ {
return new AvaloniaPropertyInvoker(this); return new AvaloniaPropertyInvoker(this);
@ -276,6 +301,11 @@ namespace Avalonia.Markup.Xaml.PortableXaml
return Property.IsReadOnly; return Property.IsReadOnly;
} }
protected override Type GetPropertyType()
{
return Property.PropertyType;
}
private class AvaloniaPropertyInvoker : XamlMemberInvoker private class AvaloniaPropertyInvoker : XamlMemberInvoker
{ {
public AvaloniaPropertyInvoker(XamlMember member) : base(member) public AvaloniaPropertyInvoker(XamlMember member) : base(member)
@ -342,22 +372,12 @@ namespace Avalonia.Markup.Xaml.PortableXaml
public class AvaloniaAttachedPropertyXamlMember : AvaloniaPropertyXamlMember public class AvaloniaAttachedPropertyXamlMember : AvaloniaPropertyXamlMember
{ {
private MethodInfo _setter;
public AvaloniaAttachedPropertyXamlMember(AvaloniaProperty property, public AvaloniaAttachedPropertyXamlMember(AvaloniaProperty property,
string attachablePropertyName, string attachablePropertyName,
MethodInfo getter, MethodInfo setter, MethodInfo getter, MethodInfo setter,
XamlSchemaContext schemaContext) XamlSchemaContext schemaContext)
: base(property, attachablePropertyName, getter, setter, schemaContext) : base(property, attachablePropertyName, getter, setter, schemaContext)
{ {
_setter = setter;
}
protected override MethodInfo LookupUnderlyingSetter()
{
return base.LookupUnderlyingSetter();
//TODO: investigate don't call base stack overflow
return _setter;
} }
} }
} }
Loading…
Cancel
Save