• Stars
    star
    310
  • Rank 134,926 (Top 3 %)
  • Language
    C#
  • License
    MIT License
  • Created almost 6 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

General purpose pluggable XAML compiler with no runtime dependencies.

XamlX

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.

default

Implemented features

  • Direct convertion of XML to objects (instantiation, setting properties, setting attached properties)
  • Create / Populate semantics
  • Properties with [DeferredContent] get assigned a Func<IServiceProvider, object> delegate which emits child nodes (can be customized, see DeferredContentTests)
  • Implicit type converting for types with static T Parse(string, [IFormatProvider]) method (e. g. int, double, TimeSpan, etc)
  • Compile-time parsing of primitive types (numbers and boolean)
  • Support for TypeConverterAttribute and a way to provide conveters for types without one.
  • Support for [Content] attribute both for direct content and for collections
  • Support for collections themselves (e. g. <List x:TypeArguments="sys:String"></List>)
  • x:Arguments Directive
  • x:TypeArguments Directive
  • x:Key Directive
  • Markup extensions with extension point for handling non-convertable values at runtime (e. g. Binding)
  • Duck-typing for markup extensions, following signatures are checked for markup extension detection (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

Architecture

The flow looks like this:

  1. Parse XAML into some basic AST (we can use different language markup parser at this point, like C#/VB in Roslyn)
  2. Transform AST via visitors. At this stage types get resolved, property values get transformed either in setting properties or collection access, etc
  3. Emit IL code

Features to implement (TODO)

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

  • x:Array Markup Extension [opt]
  • x:Name Directive [opt]
  • x:FactoryMethod Directive [opt]
  • x:Reference Markup Extension [opt]
  • xml:lang Handling in XAML [dontneed]
  • IDestinationTypeProvider (probably don't need it) [dontneed]

These are questinable due to heavy reliance on reflection:

  • IXamlTypeResolver (can be implemented in runtime via IXamlXmlNamespaceInfoProviderV1) [dontneed]
  • IXamlNameResolver (probably without forward references) [dontneed]
  • IXamlNamespaceResolver [dontneed]

These are framework-specific and can be implemented via custom transformers/emitters or custom IServiceProvider

  • x:Property Directive
  • x:Uid Directive
  • x:XData Intrinsic XAML Type
  • x:Shared Attribute
  • x:Class Directive
  • x:Subclass Directive
  • x:ClassModifier Directive
  • x:FieldModifier Directive
  • x:Member Directive
  • x:Members Directive

Won't fix:

  • IXamlSchemaContextProvider: we don't have a schema context at run time
  • IAmbientProvider - we don't have "xaml type system" at run time, only plain CLR types

Future: x:Code Intrinsic XAML Type (probably use Roslyn to inline C# code)

Possible optimizations (TODO):

  • Right now if IXamlParentStack feature is enabled, each object initialization triggers push/pop to the parent objects stack. That could be optimized out for objects that don't have anything that uses IServiceProvider (markup extensions, TypeConverter's, DeferredContent) inside of them
  • Parent's RootObject could be saved in a closure, right deferred content builder attempts to extract it from passed IServiceProvider

More Repositories

1

evhttp-sharp

libevent2-based HTTP server for C#
C#
138
star
2

CoreRPC

Extensible RPC library with Typescript client generator
C#
79
star
3

skypetab-ng

A program that adds tabs to Skypeβ„’ for Linux
C++
78
star
4

NObservable

MobX like observable state management library with Blazor support
C#
67
star
5

Avalonia.BattleCity

C#
42
star
6

Avalonia-Silk.NET-Example

C#
31
star
7

Avalonia.Ide

C#
30
star
8

avalonia-net-core-example

Example for running AvaloniaUI on .NET Core
PowerShell
28
star
9

MicroCom

IDL-based COM interop codegen
C#
25
star
10

MonoLib

Library with classes from Mono to bring modern C# language features (async/await) to .NET 2.0
C#
17
star
11

Numerge

Nuget package merging utiility
C#
17
star
12

pipedrive-net

.NET client for Pipedrive API ( https://developers.pipedrive.com/v1 )
C#
12
star
13

prowingen

prOWINgen - C#/Mono bindings for proxygen
C#
11
star
14

example-avalonia-huge-tree

C#
9
star
15

Avalonia-unit-testing-with-headless-platform

C#
9
star
16

LargeBson

C#
8
star
17

dotnext-akka-demo

Demo for .NEXT
C#
8
star
18

Nancy.Hosting.Event.2

libevent2-based host for NancyFx
C#
8
star
19

NWayland

.NET Wayland bindings, currently WIP
C#
7
star
20

avalonia-dnd-example

C#
7
star
21

hal-json-net

HAL JSON support for Json.Net
C#
6
star
22

NotifyHelper

INotifyPropertyChanged autogenerator
C#
5
star
23

evdev-sharp

A library for consuming evdev-capable devices
C#
5
star
24

SlimDock

C#
4
star
25

Bridge.Razor

Razor support for bridge.net
C#
4
star
26

monodevelop-appmenu

MonoDevelop.AppMenu
C#
4
star
27

packagereference-migrator-script

Migrates your project to new PackageReference format
C#
4
star
28

LightMvvm

C#
4
star
29

simple-clr-host

C
3
star
30

webmerge

A small utility that takes a web page and then merges scripts/css/images to a single HTML file.
C++
3
star
31

Pechka

C#
3
star
32

SkaderToy

C#
3
star
33

AvaloniaMonoDemo

C#
3
star
34

AvalonialessXamlExample

C#
2
star
35

simple-managed-websocket-server

C#
2
star
36

how-skype-fix-vulnerabilities

2
star
37

remoteui

TypeScript
2
star
38

dotnext2018spb

2
star
39

ScaleWine

A program for scaling wine virtual desktops
C++
2
star
40

CoreRPC-React-MobX

C#
2
star
41

PageAlloc

C#
2
star
42

scgi-sharp

ScgiSharp
C#
2
star
43

PhoneWave

C#
2
star
44

distributed-task-queue

Wrapper around RabbitMQ for distributing tasks (does NOT follow pub-sub concept of most AMQP-related libraries).
C#
2
star
45

dotnext2016spb

C#
2
star
46

msk.net-2016-08-11

JavaScript
2
star
47

custom-tfm-experiment

C#
1
star
48

dotnext2019spb

C#
1
star
49

simple-settings-example

C#
1
star
50

AvAotBench

C#
1
star
51

avalonia-catalog

example
C#
1
star
52

ngettext

Simple utility for extraction L._("something") from code and .pot-file generation
C#
1
star
53

ReplaceDllRepro

C#
1
star
54

baseimage-vnext

Makefile
1
star
55

acryllic-skshader-attempt

C#
1
star
56

msbuild-talk-2017-12-16

C#
1
star
57

Avalonia.XamarinForms

Xamarin forms integration (experimental and incomplete)
C#
1
star