SystemXamlHacking

Table of contents

System.Xaml.dll

This page describes our .NET 4 System.Xaml effort.

Scope

We have System.Xaml.dll which was introduced in the .NET 4.0 API.

Note that there is another effort for managed XAML parser in Moonlight land (in Mono.Xaml namespace in System.Windows.dll in its own API.

System.Xaml.dll in .NET 4 is used by WF4 and WPF, but we don't have them yet. Hence supporting WF4 or WPF XAML by this library is out of scope.

Status

High level status

Note that this page describes current status for the latest git HEAD. They don't apply to mono 2.8 or 2.10. Old implementation in 2.8 only had basic type system implementation without read/write support. In 2.10, XAML readers and writers are functional. In post-2-10 implementation, we have added a couple of missing bits and made some bugfixes.

We are almost done with it within current scope of the task. Things like ambient properties are left not implemented (are they useful without WPF?).

See also our class library status page for System.Xaml.dll.

by tasks

Since full System.Xaml is not small, I split the tasks into a set of features to make hacking achievable:

  • tasks already done
    • type system foundation: XamlLanguage, XamlType and XamlMember
    • xaml reader and writer API:
      • XamlObjectReader
      • XamlObjectWriter
      • XamlXmlReader
      • XamlXmlWriter
    • read/write of primitive types, Array and Dictionary
    • Name resolution support - somewhat hacky
    • markup extension support
    • XData/IXmlSerializable support
    • Attachable property support
    • XamlBackgroundReader (post-2.10)
    • XamlNodeQueue (post-2.10)
    • Event support (post-2.10)
    • ValueSerializer implementation - probably done.
    • StaticExtension support - probably done (I believe it is not serializable into xml)
  • optional tasks
    • Ambient property support
    • XamlDeferringLoader
    • XamlNodeList (could be done only after we find it actually used)
    • XamlLoadPermissions (almost out of scope)

by language features

All XamlLanguage types are there.

These XamlLanguage directives are supported:

  • Arguments
  • Base
  • FactoryMethod
  • _Initialization
  • _Items
  • Key
  • Lang
  • Name
  • PositionalParameters
  • TypeArguments

These XamlLanguage directives are not, but not sure if they are really used in terms of XAML readers and writers:

  • AsyncRecords
  • ClassAttributes
  • ClassModifier
  • Code
  • ConnectionId
  • FieldModifier
  • Members
  • Subclass
  • SynchronousMode
  • Shared
  • Space
  • Uid
  • _UnknownContent


Code

Classlib

I have implemented things in certain order: read objects (XamlObjectReader), write to xml (XamlXmlWriter), read back from xml (XamlXmlReader) and write to objects (XamlObjectWriter). This will apply to further XAML tests.

XamlReaderSettings, XamlWriterSettings and their derivatives are not supported much, and there is so far no plan to work on them. We'll do it per request basis.

Tests

Since we don't have testable WF4 foundation, we only have our own NUnit tests so far.

Both readers and writers differ in their behaviors in some details, we cannot make all the tests common between those readers and writers. But most of basic read/write operations can be common.

Test XmlFiles are originally generated by .NET (XamlServices.Save()) so that we can assume .NET interoperability is somewhat achieved as far as being tested (and now we can generate almost identical xml files).

The tested types are shared (see Test/System.Xaml/TestedTypes.cs). There are already fair amount of tests that strictly (often too strictly) examines reader behaviors, and such tests reside in each test class. Reader tests are shared in XamlReaderTestBase class. For writers, there is nothing much to share. Writer tests are fairly simple anyways.

Types that should be (or actually are) tested include:

  • primitive types exposed as XamlLanguage's static members, namely:
    • Array and ArrayExtension
    • Type and TypeExtension
    • NullExtension
    • Reference and cross-referenced objects, as well as x:Name
    • MemberDefinition and PropertyDefinition - not really done
    • StaticExtension - needs some work
    • XData and IXmlSerializable
      • contained by another type
      • contained by List (that disables special serialization)
  • types that are often primitive: Guid, DBNull, DateTime
  • List and Dictionary
    • simple ones
    • contains Type
    • contains Array
  • other generic types
  • custom MarkupExtension
    • with working PositionalParameters, non-top-level
    • with working PositionalParameters, top-level
  • constructor-less types i.e. with FactoryMethod
  • type and member attributed by TypeConverter