Class ExtensionMethodsForContent
Extension methods that assist or enable functionality found within the content model's content namespace ( ExtendedXmlSerializer.ContentModel.Content).
Inheritance
Inherited Members
Namespace: ExtendedXmlSerializer
Assembly: ExtendedXmlSerializer.dll
Syntax
public static class ExtensionMethodsForContent
Methods
Decorate<T>(IServiceRepository, ISpecification<TypeInfo>)
Declaration
[Obsolete("This method is being deprecated and will be removed in a future release. Use Decorate.Element.When instead.")]
public static IServiceRepository Decorate<T>(this IServiceRepository this, ISpecification<TypeInfo> specification)
where T : IElement
Parameters
IServiceRepository
this
|
ISpecification<System.Reflection.TypeInfo>
specification
|
Returns
IServiceRepository
|
Type Parameters
T
|
DecorateContent<T>(IServiceRepository, ISpecification<TypeInfo>)
Declaration
[Obsolete("This method is being deprecated and will be removed in a future release. Use Decorate.Contents.When instead.")]
public static IServiceRepository DecorateContent<T>(this IServiceRepository this, ISpecification<TypeInfo> specification)
where T : IContents
Parameters
IServiceRepository
this
|
ISpecification<System.Reflection.TypeInfo>
specification
|
Returns
IServiceRepository
|
Type Parameters
T
|
DecorateContent<TSpecification, T>(IServiceRepository)
Declaration
[Obsolete("This method is being deprecated and will be removed in a future release. Use Decorate.Contents.When instead.")]
public static IServiceRepository DecorateContent<TSpecification, T>(this IServiceRepository this)
where TSpecification : ISpecification<TypeInfo> where T : IContents
Parameters
IServiceRepository
this
|
Returns
IServiceRepository
|
Type Parameters
TSpecification
|
T
|
DecorateContentsWith<T>(IServiceRepository)
Convenience method for extension authors. This is used to establish a context to decorate the container's IContents component.
Declaration
public static ContentsDecorationContext<T> DecorateContentsWith<T>(this IServiceRepository this)
where T : IContents
Parameters
IServiceRepository
this
The repository to configure (used within an extension). |
Returns
ContentsDecorationContext<T>
The configured repository. |
Type Parameters
T
The implementation type, of type IContents. |
DecorateElementWith<T>(IServiceRepository)
Convenience method for extension authors. This is used to establish a fluent context which can further be used to decorate the container's IElement component.
Declaration
public static ElementDecorationContext<T> DecorateElementWith<T>(this IServiceRepository this)
where T : IElement
Parameters
IServiceRepository
this
The repository to configure. |
Returns
ElementDecorationContext<T>
The configured repository. |
Type Parameters
T
The implementation type, of type IElement. |
Emit(IConfigurationContainer, IEmitBehavior)
Used to control and determine when content is emitted during serialization. This is a general-purpose configuration that works across every type encountered by the serializer. Use the EmitBehaviors class to utilize one of the built-in (and identified 😁) behaviors, or implement your own IEmitBehavior.
Declaration
public static IConfigurationContainer Emit(this IConfigurationContainer this, IEmitBehavior behavior)
Parameters
IConfigurationContainer
this
The container to configure. |
IEmitBehavior
behavior
The behavior to apply to the container. |
Returns
IConfigurationContainer
The configured container. |
EmitWhen<T>(ITypeConfiguration<T>, Func<T, Boolean>)
Configures a type configuration so that instances of its type only emit when the provided condition is met.
Declaration
public static ITypeConfiguration<T> EmitWhen<T>(this ITypeConfiguration<T> this, Func<T, bool> specification)
Parameters
ITypeConfiguration<T>
this
The type configuration to configure. |
System.Func<T, System.Boolean>
specification
The specification to determine the condition on when to emit. |
Returns
ITypeConfiguration<T>
The configured type configuration. |
Type Parameters
T
The instance type. |
EmitWhen<T, TMember>(IMemberConfiguration<T, TMember>, Func<TMember, Boolean>)
Configures a member configuration to only emit when its value meets certain criteria.
Declaration
public static IMemberConfiguration<T, TMember> EmitWhen<T, TMember>(this IMemberConfiguration<T, TMember> this, Func<TMember, bool> specification)
Parameters
IMemberConfiguration<T, TMember>
this
The member to configure. |
System.Func<TMember, System.Boolean>
specification
The specification to use to determine whether or not to emit the member, based on value. |
Returns
IMemberConfiguration<T, TMember>
The configured member. |
Type Parameters
T
The containing type of the member. |
TMember
The member type. |
EmitWhenInstance<T, TMember>(IMemberConfiguration<T, TMember>, Func<T, Boolean>)
Configures a member configuration to only emit when a condition of its containing instance is met. This is useful for when a data value from another member in another part of the containing instance is needed to determine whether or not to emit the (currently) configured member.
Declaration
public static IMemberConfiguration<T, TMember> EmitWhenInstance<T, TMember>(this IMemberConfiguration<T, TMember> this, Func<T, bool> specification)
Parameters
IMemberConfiguration<T, TMember>
this
The member to configure. |
System.Func<T, System.Boolean>
specification
|
Returns
IMemberConfiguration<T, TMember>
The configured member. |
Type Parameters
T
The containing type of the member. |
TMember
The member type. |
EnableImplicitlyDefinedDefaultValues(IConfigurationContainer)
This is intended to circumvent default behavior which throws an exception for primitive data types when there is no content provided for their elements.
For example, say you have a boolean element defined as such: <Boolean></Boolean>
or, perhaps its long-form equivalent <Boolean></Boolean>
.
Either one of these by default will throw a System.FormatException. Configuring the container with EnableImplicitlyDefinedDefaultValues(IConfigurationContainer) will allow the use of empty values within document elements such as the above without throwing an exception.
Declaration
public static IConfigurationContainer EnableImplicitlyDefinedDefaultValues(this IConfigurationContainer this)
Parameters
IConfigurationContainer
this
The container to configure. |
Returns
IConfigurationContainer
The configured container. |
EnableParameterizedContent(IConfigurationContainer)
Allows content to be read as parameters for a constructor call to activate an object, rather than the more traditional route of activating an object and its content read as property assignments. This is preferred -- required, even -- if your model is comprised of immutable objects.
Note that there are several requirements for a class to be successfully processed:
- only public fields / properties are considered
- any public fields (spit) must be readonly
- any public properties must have a get but not a set (on the public API, at least)
- there must be exactly one interesting constructor, with parameters that are a case-insensitive match for each field/property in some order (i.e. there must be an obvious 1:1 mapping between members and constructor parameter names)
Declaration
public static IConfigurationContainer EnableParameterizedContent(this IConfigurationContainer this)
Parameters
IConfigurationContainer
this
The container to configure. |
Returns
IConfigurationContainer
The configured container. |
See Also
EnableParameterizedContentWithPropertyAssignments(IConfigurationContainer)
This is a less strict version of EnableParameterizedContent(IConfigurationContainer). Using this version, parameterized content works the same as EnableParameterizedContent(IConfigurationContainer) but in addition, all properties defined in the deserialized document are also considered and assigned to the target instance if the property is writable.
Declaration
public static IConfigurationContainer EnableParameterizedContentWithPropertyAssignments(this IConfigurationContainer this)
Parameters
IConfigurationContainer
this
The container to configure. |
Returns
IConfigurationContainer
The configured container. |
EnableReaderContext(IConfigurationContainer)
Intended for extension authors, and enables a reader context on the deserialization process. Extension authors can use ContentsHistory to retrieve this history of objects being parsed and activated to the current point of the graph. This is valuable when parsing object graphs with many internal properties which in turn have their own set of complex properties.
Declaration
public static IConfigurationContainer EnableReaderContext(this IConfigurationContainer this)
Parameters
IConfigurationContainer
this
The container to configure. |
Returns
IConfigurationContainer
The configured container. |
Ignore(IConfigurationContainer, MemberInfo)
Ignores a member so that it is not emitted during serialization, and is not read in during deserialization, even if the content is specified in the document. Note that this establishes a "blacklist" policy so that members that are not ignored get processed.
Declaration
public static IConfigurationContainer Ignore(this IConfigurationContainer this, MemberInfo member)
Parameters
IConfigurationContainer
this
The container to configure. |
System.Reflection.MemberInfo
member
The member to ignore. |
Returns
IConfigurationContainer
The configured container. |
Ignore(IConfigurationContainer, TypeInfo)
Marks the specified type as ignored, meaning it will not emit or read when encountered in a graph.
Declaration
public static IConfigurationContainer Ignore(this IConfigurationContainer this, TypeInfo type)
Parameters
IConfigurationContainer
this
The container to configure. |
System.Reflection.TypeInfo
type
The type to mark as ignored. |
Returns
IConfigurationContainer
The configured container. |
Ignore<T>(ITypeConfiguration<T>)
Marks the specified type as ignored, meaning it will not emit or read when encountered in a graph.
Declaration
public static ITypeConfiguration<T> Ignore<T>(this ITypeConfiguration<T> this)
Parameters
ITypeConfiguration<T>
this
The type configuration to configure. |
Returns
ITypeConfiguration<T>
The configured type configuration. |
Type Parameters
T
The type under configuration. |
Ignore<T, TMember>(IMemberConfiguration<T, TMember>)
Ignores a member so that it is not emitted during serialization, and is not read in during deserialization, even if the content is specified in the document. Note that this establishes a "blacklist" policy so that members that are not ignored get processed.
Declaration
public static IMemberConfiguration<T, TMember> Ignore<T, TMember>(this IMemberConfiguration<T, TMember> this)
Parameters
IMemberConfiguration<T, TMember>
this
The member to configure. |
Returns
IMemberConfiguration<T, TMember>
The configured member. |
Type Parameters
T
The instance type. |
TMember
The member type. |
Include(IMemberConfiguration)
Includes a member so that it is emitted during serialization and read during deserialization. Note that including a member establishes a "whitelist" policy so that only members that are explicitly included are considered for processing.
Declaration
public static IMemberConfiguration Include(this IMemberConfiguration this)
Parameters
IMemberConfiguration
this
The member to configure. |
Returns
IMemberConfiguration
The configured member. |
Include(ITypeConfiguration)
Marks a type as "allowed" so that it is emitted during serialization and read during deserialization. Note that including a type establishes an "allowed-only" policy so that only types that are explicitly included are considered for processing.
Declaration
public static ITypeConfiguration Include(this ITypeConfiguration this)
Parameters
ITypeConfiguration
this
The type configuration to configure. |
Returns
ITypeConfiguration
The configured type configuration. |
Include<T>(ITypeConfiguration<T>)
Marks a type as "allowed" so that it is emitted during serialization and read during deserialization. Note that including a type establishes an "allowed-only" policy so that only types that are explicitly included are considered for processing.
Declaration
public static ITypeConfiguration<T> Include<T>(this ITypeConfiguration<T> this)
Parameters
ITypeConfiguration<T>
this
The type configuration to configure. |
Returns
ITypeConfiguration<T>
The configured type configuration. |
Type Parameters
T
The type under configuration. |
Include<T, TMember>(IMemberConfiguration<T, TMember>)
Includes a member so that it is emitted during serialization and read during deserialization. Note that including a member establishes a "whitelist" policy so that only members that are explicitly included are considered for processing.
Declaration
public static IMemberConfiguration<T, TMember> Include<T, TMember>(this IMemberConfiguration<T, TMember> this)
Parameters
IMemberConfiguration<T, TMember>
this
The member to configure. |
Returns
IMemberConfiguration<T, TMember>
The configured member. |
Type Parameters
T
The type that contains the member. |
TMember
The type of the member's value. |
IncludeConfiguredMembers(IConfigurationContainer)
Convenience method to iterate through all explicitly configured types and include all explicitly configured members. Only these members will be considered to emit content during serialization as well as reading it during deserialization.
Declaration
public static IConfigurationContainer IncludeConfiguredMembers(this IConfigurationContainer this)
Parameters
IConfigurationContainer
this
The container to configure. |
Returns
IConfigurationContainer
The configured container. |
IncludeConfiguredMembers<T>(ITypeConfiguration<T>)
Convenience method to iterate through all explicitly configured members of a type and mark them as included. Only these members will be considered to emit content during serialization as well as reading it during deserialization.
Declaration
public static ITypeConfiguration<T> IncludeConfiguredMembers<T>(this ITypeConfiguration<T> this)
Parameters
ITypeConfiguration<T>
this
The type to configure. |
Returns
ITypeConfiguration<T>
The configured type. |
Type Parameters
T
The type under configuration. |
OnlyConfiguredProperties(IConfigurationContainer)
Declaration
[Obsolete("This method will be removed in a future release. Use IConfigurationContainer.IncludeConfiguredMembers instead.")]
public static IConfigurationContainer OnlyConfiguredProperties(this IConfigurationContainer this)
Parameters
IConfigurationContainer
this
|
Returns
IConfigurationContainer
|
OnlyConfiguredProperties<T>(ITypeConfiguration<T>)
Declaration
[Obsolete("This method will be removed in a future release. Use ITypeConfiguration<T>.IncludeConfiguredMembers instead.")]
public static ITypeConfiguration<T> OnlyConfiguredProperties<T>(this ITypeConfiguration<T> this)
Parameters
ITypeConfiguration<T>
this
|
Returns
ITypeConfiguration<T>
|
Type Parameters
T
|
OptimizeConverters(IConfigurationContainer)
Declaration
[Obsolete("This is considered a deprecated feature and will be removed in a future release.")]
public static IConfigurationContainer OptimizeConverters(this IConfigurationContainer this)
Parameters
IConfigurationContainer
this
|
Returns
IConfigurationContainer
|
OptimizeConverters(IConfigurationContainer, IAlteration<IConverter>)
Declaration
[Obsolete("This is considered a deprecated feature and will be removed in a future release.")]
public static IConfigurationContainer OptimizeConverters(this IConfigurationContainer this, IAlteration<IConverter> optimizations)
Parameters
IConfigurationContainer
this
|
IAlteration<IConverter>
optimizations
|
Returns
IConfigurationContainer
|
WithDefaultMonitor(IConfigurationContainer, ISerializationMonitor)
Assigns a default serialization monitor for a configuration container. A serialization monitor is a component that gets notified whenever there is a serialization such as OnSerializing, OnSerialized, as well as deserialization events such as OnDeserializing, OnDeserialized, etc.
The default serialization monitor is applied for every type that is serialized with the serializer that the configured container creates. Use WithMonitor<T>(ITypeConfiguration<T>, ISerializationMonitor<T>) on a type configuration to apply a monitor to a specific type.
Declaration
public static IConfigurationContainer WithDefaultMonitor(this IConfigurationContainer this, ISerializationMonitor monitor)
Parameters
IConfigurationContainer
this
The configuration container to configure. |
ISerializationMonitor
monitor
The monitor to assign as the default monitor. |
Returns
IConfigurationContainer
The configured container. |
See Also
WithEnumerableSupport(IConfigurationContainer)
Adds support for instances and property types that are explicitly specified as IEnumerable{T}
. If an object is
of a type of IEnumerable
(essentially, a deferred query), it will be evaluated as a System.Collections.Generic.List`1 and
saved as such as required by either the instance or property in the object graph.
Declaration
public static IConfigurationContainer WithEnumerableSupport(this IConfigurationContainer this)
Parameters
IConfigurationContainer
this
The configuration container to configure. |
Returns
IConfigurationContainer
The configured configuration container. |
See Also
WithInterceptor<T>(ITypeConfiguration<T>, ISerializationInterceptor)
Applies a generalized interceptor for type configuration. An interceptor participates in the serialization pipeline by being introduced during key serialization and deserialization events.
Declaration
public static ITypeConfiguration<T> WithInterceptor<T>(this ITypeConfiguration<T> this, ISerializationInterceptor interceptor)
Parameters
ITypeConfiguration<T>
this
The type to intercept. |
ISerializationInterceptor
interceptor
The interceptor to apply to a type. |
Returns
ITypeConfiguration<T>
The configured type configuration. |
Type Parameters
T
The type argument of the type configuration being configured. |
See Also
WithInterceptor<T>(ITypeConfiguration<T>, ISerializationInterceptor<T>)
Applies an interceptor for type configuration. An interceptor participates in the serialization pipeline by being introduced during key serialization and deserialization events.
Declaration
public static ITypeConfiguration<T> WithInterceptor<T>(this ITypeConfiguration<T> this, ISerializationInterceptor<T> interceptor)
Parameters
ITypeConfiguration<T>
this
The type to intercept. |
ISerializationInterceptor<T>
interceptor
The interceptor to apply to a type. |
Returns
ITypeConfiguration<T>
The configured type configuration. |
Type Parameters
T
The type argument of the type configuration being configured. |
See Also
WithMonitor<T>(ITypeConfiguration<T>, ISerializationMonitor<T>)
Applies a serialization monitor to a specific type. A serialization monitor is a component that gets notified whenever there is a serialization such as OnSerializing, OnSerialized, as well as deserialization events such as OnDeserializing, OnDeserialized, etc.
Note that calling this method will establish a default monitor if one has not already been assigned. If you also want to use a default monitor in addition to type-specific monitors, call the WithDefaultMonitor(IConfigurationContainer, ISerializationMonitor) first before calling this method on any types.
Declaration
public static ITypeConfiguration<T> WithMonitor<T>(this ITypeConfiguration<T> this, ISerializationMonitor<T> monitor)
Parameters
ITypeConfiguration<T>
this
The type configuration to configure. |
ISerializationMonitor<T>
monitor
The monitor to apply to the specified type. |
Returns
ITypeConfiguration<T>
The configured type configuration. |
Type Parameters
T
The type to monitor. |