General purpose pluggable XAML compiler with no runtime dependencies. Currently being used by Avalonia project as the XAML engine.
The compiler isn't tied to Avalonia in any way, shape or form and can be used for any purposes
by configuring XamlLanguageTypeMappings
to match the needs of your particular framework.
Further customization can be done by AST manipulations, see examples of those in Avalonia repository.
[DeferredContent]
get assigned a Func<IServiceProvider, object>
delegate which emits child nodes (can be customized, see DeferredContentTests)static T Parse(string, [IFormatProvider])
method (e. g. int
, double
, TimeSpan
, etc)[Content]
attribute both for direct content and for collections<List x:TypeArguments="sys:String"></List>
)Binding
)T
is anything that's not System.Object
):T ProvideValue();
T ProvideValue(IServiceProvider provider);
object ProvideValue();
object ProvideValue(IServiceProvider provider);
If strongly typed markup extension overload is available, it's used to avoid unnecessary casts and boxing
x:Null Markup Extension (intrinsic: ldnull
)
x:Type Markup Extension (intrinsic: ldtoken
+ Type.FromRuntimeHandle
)
x:Static Markup Extension (intrinsic: properties (call get_PropName
), fields (ldsfld
), constants/enums (ldc_*
/ldstr
)
IRootObjectProvider
UsableDuringInitializationAttribute (assign first, set properties/contents later)
ISupportInitialize
XAML parents stack (see IXamlParentsStack in tests) as an lightweight alternative for IAmbientProvider
Support for mc:Ignorable
IProvideValueTarget (property name is provided for regular properties, RuntimeMethodInfo is provided for attached ones)
IUriContext
Primitive types (sys:String, sys:Int32, sys:TimeSpan etc) https://docs.microsoft.com/en-us/dotnet/framework/xaml-services/built-in-types-for-common-xaml-language-primitives
Runtime xmlns information via IXamlXmlNamespaceInfoProvider
(provides Dictionary<string, List<(string clrNamespace, string asm)>
)
xml:space Handling in XAML (automatically via XmlReader)
Event handlers from codebehind
The flow looks like this:
Features marked with [dontneed] aren't required for the Avalonia project, but might be implemented later if the need arises. Features marked with [opt] are considered optional and will be implemented after non-optional features
These are questinable due to heavy reliance on reflection:
IXamlXmlNamespaceInfoProviderV1
) [dontneed]
These are framework-specific and can be implemented via custom transformers/emitters or custom IServiceProvider
Future: x:Code Intrinsic XAML Type (probably use Roslyn to inline C# code)
TypeConverter
's, DeferredContent
) inside of themRootObject
could be saved in a closure, right deferred content builder attempts to extract it fromIServiceProvider