|
|
@ -1,5 +1,6 @@ |
|
|
using System; |
|
|
using System; |
|
|
using System.Collections.Generic; |
|
|
using System.Collections.Generic; |
|
|
|
|
|
using System.Linq; |
|
|
using Avalonia.Controls; |
|
|
using Avalonia.Controls; |
|
|
using Avalonia.Data.Core; |
|
|
using Avalonia.Data.Core; |
|
|
using Avalonia.Data.Core.Plugins; |
|
|
using Avalonia.Data.Core.Plugins; |
|
|
@ -53,6 +54,9 @@ namespace Avalonia.Markup.Xaml.MarkupExtensions.CompiledBindings |
|
|
case IStronglyTypedStreamElement stream: |
|
|
case IStronglyTypedStreamElement stream: |
|
|
node = new StreamNode(stream.CreatePlugin()); |
|
|
node = new StreamNode(stream.CreatePlugin()); |
|
|
break; |
|
|
break; |
|
|
|
|
|
case ITypeCastElement typeCast: |
|
|
|
|
|
node = new StrongTypeCastNode(typeCast.Type, typeCast.Cast); |
|
|
|
|
|
break; |
|
|
default: |
|
|
default: |
|
|
throw new InvalidOperationException($"Unknown binding path element type {element.GetType().FullName}"); |
|
|
throw new InvalidOperationException($"Unknown binding path element type {element.GetType().FullName}"); |
|
|
} |
|
|
} |
|
|
@ -66,6 +70,9 @@ namespace Avalonia.Markup.Xaml.MarkupExtensions.CompiledBindings |
|
|
internal SourceMode SourceMode => _elements.Count > 0 && _elements[0] is IControlSourceBindingPathElement ? SourceMode.Control : SourceMode.Data; |
|
|
internal SourceMode SourceMode => _elements.Count > 0 && _elements[0] is IControlSourceBindingPathElement ? SourceMode.Control : SourceMode.Data; |
|
|
|
|
|
|
|
|
internal object RawSource { get; } |
|
|
internal object RawSource { get; } |
|
|
|
|
|
|
|
|
|
|
|
public override string ToString() |
|
|
|
|
|
=> string.Concat(_elements.Select(e => e.ToString())); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public class CompiledBindingPathBuilder |
|
|
public class CompiledBindingPathBuilder |
|
|
@ -126,6 +133,12 @@ namespace Avalonia.Markup.Xaml.MarkupExtensions.CompiledBindings |
|
|
return this; |
|
|
return this; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public CompiledBindingPathBuilder TypeCast<T>() |
|
|
|
|
|
{ |
|
|
|
|
|
_elements.Add(new TypeCastPathElement<T>()); |
|
|
|
|
|
return this; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public CompiledBindingPathBuilder SetRawSource(object rawSource) |
|
|
public CompiledBindingPathBuilder SetRawSource(object rawSource) |
|
|
{ |
|
|
{ |
|
|
_rawSource = rawSource; |
|
|
_rawSource = rawSource; |
|
|
@ -157,6 +170,9 @@ namespace Avalonia.Markup.Xaml.MarkupExtensions.CompiledBindings |
|
|
public IPropertyInfo Property { get; } |
|
|
public IPropertyInfo Property { get; } |
|
|
|
|
|
|
|
|
public Func<WeakReference<object>, IPropertyInfo, IPropertyAccessor> AccessorFactory { get; } |
|
|
public Func<WeakReference<object>, IPropertyInfo, IPropertyAccessor> AccessorFactory { get; } |
|
|
|
|
|
|
|
|
|
|
|
public override string ToString() |
|
|
|
|
|
=> $".{Property.Name}"; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
internal interface IStronglyTypedStreamElement : ICompiledBindingPathElement |
|
|
internal interface IStronglyTypedStreamElement : ICompiledBindingPathElement |
|
|
@ -164,6 +180,13 @@ namespace Avalonia.Markup.Xaml.MarkupExtensions.CompiledBindings |
|
|
IStreamPlugin CreatePlugin(); |
|
|
IStreamPlugin CreatePlugin(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
internal interface ITypeCastElement : ICompiledBindingPathElement |
|
|
|
|
|
{ |
|
|
|
|
|
Type Type { get; } |
|
|
|
|
|
|
|
|
|
|
|
Func<object, object> Cast { get; } |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
internal class TaskStreamPathElement<T> : IStronglyTypedStreamElement |
|
|
internal class TaskStreamPathElement<T> : IStronglyTypedStreamElement |
|
|
{ |
|
|
{ |
|
|
public static readonly TaskStreamPathElement<T> Instance = new TaskStreamPathElement<T>(); |
|
|
public static readonly TaskStreamPathElement<T> Instance = new TaskStreamPathElement<T>(); |
|
|
@ -181,6 +204,9 @@ namespace Avalonia.Markup.Xaml.MarkupExtensions.CompiledBindings |
|
|
internal class SelfPathElement : ICompiledBindingPathElement, IControlSourceBindingPathElement |
|
|
internal class SelfPathElement : ICompiledBindingPathElement, IControlSourceBindingPathElement |
|
|
{ |
|
|
{ |
|
|
public static readonly SelfPathElement Instance = new SelfPathElement(); |
|
|
public static readonly SelfPathElement Instance = new SelfPathElement(); |
|
|
|
|
|
|
|
|
|
|
|
public override string ToString() |
|
|
|
|
|
=> "$self"; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
internal class AncestorPathElement : ICompiledBindingPathElement, IControlSourceBindingPathElement |
|
|
internal class AncestorPathElement : ICompiledBindingPathElement, IControlSourceBindingPathElement |
|
|
@ -193,6 +219,9 @@ namespace Avalonia.Markup.Xaml.MarkupExtensions.CompiledBindings |
|
|
|
|
|
|
|
|
public Type AncestorType { get; } |
|
|
public Type AncestorType { get; } |
|
|
public int Level { get; } |
|
|
public int Level { get; } |
|
|
|
|
|
|
|
|
|
|
|
public override string ToString() |
|
|
|
|
|
=> $"$parent[{AncestorType?.Name},{Level}]"; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
internal class VisualAncestorPathElement : ICompiledBindingPathElement, IControlSourceBindingPathElement |
|
|
internal class VisualAncestorPathElement : ICompiledBindingPathElement, IControlSourceBindingPathElement |
|
|
@ -217,6 +246,9 @@ namespace Avalonia.Markup.Xaml.MarkupExtensions.CompiledBindings |
|
|
|
|
|
|
|
|
public INameScope NameScope { get; } |
|
|
public INameScope NameScope { get; } |
|
|
public string Name { get; } |
|
|
public string Name { get; } |
|
|
|
|
|
|
|
|
|
|
|
public override string ToString() |
|
|
|
|
|
=> $"#{Name}"; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
internal class ArrayElementPathElement : ICompiledBindingPathElement |
|
|
internal class ArrayElementPathElement : ICompiledBindingPathElement |
|
|
@ -229,5 +261,24 @@ namespace Avalonia.Markup.Xaml.MarkupExtensions.CompiledBindings |
|
|
|
|
|
|
|
|
public int[] Indices { get; } |
|
|
public int[] Indices { get; } |
|
|
public Type ElementType { get; } |
|
|
public Type ElementType { get; } |
|
|
|
|
|
public override string ToString() |
|
|
|
|
|
=> $"[{string.Join(",", Indices)}]"; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
internal class TypeCastPathElement<T> : ITypeCastElement |
|
|
|
|
|
{ |
|
|
|
|
|
private static object TryCast(object obj) |
|
|
|
|
|
{ |
|
|
|
|
|
if (obj is T result) |
|
|
|
|
|
return result; |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Type Type => typeof(T); |
|
|
|
|
|
|
|
|
|
|
|
public Func<object, object> Cast => TryCast; |
|
|
|
|
|
|
|
|
|
|
|
public override string ToString() |
|
|
|
|
|
=> $"({Type.FullName})"; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|