-
Notifications
You must be signed in to change notification settings - Fork 47
API Overview
At the heart of ExtendedXmlSerializer's configuration sits a fluent API. Example:
IExtendedXmlSerializer serializer = new ConfigurationContainer()
.UseEncryptionAlgorithm(new CustomEncryption())
.Type<Person>() // Configuration of Person class
.Member(p => p.Password) // First member
.Name("P")
.Encrypt()
.Member(p => p.Name) // Second member
.Name("T")
.Type<TestClass>() // Configuration of another class
.CustomSerializer(new TestClassSerializer())
.Create();
As such, there are three primary configuration components that you will work with to configure ExtendedXmlSerializer:
ConfigurationContainer
TypeConfiguration<T>
MemberConfiguration<T, TMember>
We start this API Overview by exploring these three configuration elements, then move onto other primary components used throughout ExtendedXmlSerializer.
The ConfigurationContainer
is considered the root-level entry object in ExtendedXmlSerializer. All root serializers created in ExtendedXmlSerializer are done through a ConfigurationContainer
after it has been created and configured.
Is is through the use of the ConfigurationContainer
's Type<T>
method call [link] that we are able to configure types, which we explore in the next section.
But first. :) A quick note about configuration profiles. Configuration containers can be configured via configuration profiles, which are pre-configured, encapsulated components that can be shared across projects that configure configuration containers in a particular away. You can see these in action here.
A type configuration is a root-level component in ExtendedXmlSerializer, and is accessed by calling the Type<T>
method [link] on the ConfigurationContainer
.
With a TypeConfiguration
configuration object, a system is able to configure a type and how it is processed during the serialization and deserialization process. The system can further configure members of a type by calling their respective Member
method [link] on the TypeConfiguration
object. Doing so returns a MemberConfiguration
object which we discuss next.
The member configuration is where configuration occurs for a type's member within a configuration container. Using this object, a system can configure how a type's member is serialized and deserialized during their respective processes.
Now that we have explored the configuration components, let's briefly dive into the other featured components used throughout ExtendedXmlSerializer. These components are not typically used or seen by a casual user of ExtendedXmlSerializer, and are intended to be utilized by extension authors, if they should be so brave to wander into such territory. 😅
This is the root element in the extension model in ExtendedXmlSerializer. This is to extensions what the ConfigurationContainer
is to configuration.
The serializer extension is used to extend a serializer by taking part of its service registration pipeline (think: dependency injection). Extensions are added as a list and are then processed in the order that they are added.
You can see the ISerializerExtension
in action within the Create an Extension example scenario.
This interface is what is used to request and resolve content serializers for different types within the object graph as it is being processsed. This interface is used quite extensively in extensions, mostly by way of decoration and used to intercept in favor of another implementation of IContents
in the pipeline. You can see an example of this in the example scenario.
Also known as a content serializer as it sits in the ExtendedXmlSerializer.ContentModel
namespace. This is the internal serializer that is returned whenever a serializer for a particular type is resolved. When a particular type is encountered while traversing an object graph, this is the serializer type that is returned via the IContents
interface.
Whereas the ISerializer
content serializer above is meant for complex serialization and deserialization, the IConverter
is meant for simple deserialization. The IConverter
is used via registration to serialize objects to and from a string
directly. That is, given a string
, an IConverter
will be able to create a object from it, and conversely format a given object into a resulting string
.
You can see more of this in the Register a Converter example scenario.
Finally, a word about IElement
. This is a specialized component that is used to register different types for emitting elements into the XML document. By default, ExtendedXmlSerializer captures the following element types:
- Arrays
- Generic Types
- Element (default)
While not a common, other types can be used and this component warrants mention in the overview here.
ConfigurationContainer
TypeConfiguration
MemberConfiguration
ISerializerExtension
IContents
ISerializer
IConverter
IElement