aaubry/YamlDotNet — pull request #58 by xoofx (2013-10-08 15:15:35+00:00)
Title: New serializer code

Hi!

This pull-request contains some substantial changes to YamlDotNet:

- The library has been merged into a **single assembly** YamlDotNet (old RepresentationModel)
- The library is now compiling against **Portable Class Library** (in order to be able to use it on Windows RT, Windows Phone8...etc.). It means that there is now a minimum requirement of .NET 4.0+
- The serializer infrastructure has been completely rewritten and put in the namespace `YamlDotNet.Serialization`. This is the most critical change in this pull request. There was several reasons for this:

- The main reason is that I wanted to have a single and unified infrastructure for serializing/deserializing, hopefully easier to manage. There is less abstraction in the new code, without reducing the features.
- All serializers are inheriting from `IYamlSerializable`. This same interface is used internally to perform the whole serialization but can be used to register a custom serializer for a specific type. There is also a `IYamlSerializableFactory` to allow dynamic creation of serializers.
- There is now a single entry point for serializing, deserializing through the class `Serializer`
- To configure the behaviour of the serializer,there is now a `SerializerSettings` that can be passed to the Serializer.
- In `SerializerSettings` there are a couple of new options:
- Some booleans like `LimitFlowSequence` or `IndentLess`
- It is possible to attach some attributes to a member (type, field, property) through the `Attributes` property, useful when you don't own a library but want to customize how fields/properties are serialized.
- Because it is no longer possible to iterate on assemblies of Current AppDomain, it is required to register assembly with `RegisterAssembly` used for lookup types (outside of the current assembly and System.Core/mscorlib assembly)
- The type system is now using a centralized infrastructure through `IObjectDescriptor` and `IMemberDescriptor` and their specialized implementations in `YamlDotNet.Serialization.Descriptors` (`ObjectDescriptor`, `DictionaryDescriptor`, `CollectionDescriptor`)
- Internal serializers are in the namespace `YamlDotNet.Serialization.Serializers`. Some of them are made internal in order to avoid exposing unnecessary API to users. For example, `PrimitiveSerializer`is responsible for serializing and deserializing all primitives supported by YAML.
- Serialization is supporting
- Properties exposed with only a getter but their content can be filled by the serialization.
- Forward alias/anchor reference (I discovered them in the tests!)
- Custom collections/dictionaries that have their own additional properties that need to be serialized. In this case, there is a new kind of serialization using the special field `~Items` (See SerializerTests2 for more details).
- All tests have been updated and are passing fine. There was only a test using IConvertible that was not converted (as there is no longer any TypeConverter in PCL). There is also one test in Dynamic, `TestNonexistingMember`, not sure why.
- Schemas from 1.2 specs have been integrated in the namespace `YamlDotNet.Schemas`. They are not entirely plugged in and are still used sporadically (mainly to parse booleans like 'True'...etc.), but there is an infrastructure, so It could be used more extensively at some point.
- The behaviour of this new serializer could break existing serialized object when deserializing, so this is not an easy update.
- And I have probably forgotten a couple of things... but...

Wow, this is big! Okay, this pull-request is probably not going to be easy to integrate directly, considering the changes! ;) Perhaps some of the decisions I made are going against some of your plans or current usage, but let me know what do you think about it and if we can arrange things.

Cheers!