Show / Hide Table of Contents

Class ExtensionMethodsForConfiguration

Extension methods that assist or enable functionality found within the configuration namespace ( ExtendedXmlSerializer.Configuration).

Inheritance
System.Object
ExtensionMethodsForConfiguration
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: ExtendedXmlSerializer
Assembly: ExtendedXmlSerializer.dll
Syntax
public static class ExtensionMethodsForConfiguration

Methods

Add<T>(IRootContext)

Adds an extension of the provided type to the provided context. This will be done by attempting to locate a singleton on the provided type, and if that isn't found, activate it by calling its public constructor.

Declaration
public static T Add<T>(this IRootContext this)
    where T : ISerializerExtension
Parameters
IRootContext this

The configuration context (usually a configuration container) with which to add the created serializer extension.

Returns
T

The created and added extension.

Type Parameters
T

The serializer extension type to locate and add.

Add<T>(IRootContext, Func<T>)

Adds an extension to the provided context by invoking the provided factory method and adding it to the context.

Declaration
public static T Add<T>(this IRootContext this, Func<T> create)
    where T : ISerializerExtension
Parameters
IRootContext this

The configuration context (usually a configuration container) with which to add the created serializer extension.

System.Func<T> create

The factory used to create the extension of the requested type.

Returns
T

The created and added extension.

Type Parameters
T

The serializer extension type to create and add.

AllowedReferenceTypes(IConfigurationContainer)

Retrieves the current "whitelist" of allowed types on a configuration container. If specified and populated, these are the only types that can have EnableReferences(IConfigurationContainer) called on them. Note that if both whitelist and blacklists are populated, the whitelist takes precedence.

Declaration
public static ICollection<TypeInfo> AllowedReferenceTypes(this IConfigurationContainer this)
Parameters
IConfigurationContainer this

The configuration container to query.

Returns
System.Collections.Generic.ICollection<System.Reflection.TypeInfo>

The current allowed types that can be reference-enabled.

AllowMultipleReferences(IConfigurationContainer)

This enables multiple references to be allowed in the graph without throwing an exception. By default if multiple instances of the same reference are found in an object graph that is being serialized, this throws an exception. This overrides the the default setting and allows the serialization to occur. Note that this does not impact cyclical references and these will still throw an exception if encountered and EnableReferences(IConfigurationContainer) is not configured on the container.

Declaration
public static IConfigurationContainer AllowMultipleReferences(this IConfigurationContainer this)
Parameters
IConfigurationContainer this

The configuration container to configure.

Returns
IConfigurationContainer

The configured configuration container.

See Also
https://github.com/ExtendedXmlSerializer/home/issues/583

Apply<T>(IRootContext)

Used to apply a new serializer extension of the provided type. If an extension already exists in the provided context, it is returned. Otherwise, it will attempt to locate a singleton on the provided type, and if that isn't found, activate it by calling its public constructor.

Declaration
public static IRootContext Apply<T>(this IRootContext this)
    where T : class, ISerializerExtension
Parameters
IRootContext this

The configuration context (usually a configuration container) to locate the provided serializer extension type.

Returns
IRootContext

The configured context with the requested extension applied to it.

Type Parameters
T

The serializer extension type to apply.

Apply<T>(IRootContext, Func<T>)

Used to apply a new serializer extension of the provided type. If an extension already exists in the provided context, it is returned. Otherwise, it will use the provided factory to create the serializer and register it with the provided context.

Declaration
public static IRootContext Apply<T>(this IRootContext this, Func<T> create)
    where T : class, ISerializerExtension
Parameters
IRootContext this

The configuration context (usually a configuration container) to locate the provided serializer extension type.

System.Func<T> create

The factory used to create the extension of the requested type, if an instance of its type does not already exist.

Returns
IRootContext

The configured context with the requested extension applied to it.

Type Parameters
T

The serializer extension type to apply.

As<T>(MemberInfo)

Convenience method to create a strongly-typed MemberInfo object that can be used to query from a configuration container via the MemberBy<T>(ITypeConfiguration<T>, MemberInfo) method call.

Declaration
public static MemberInfo<T> As<T>(this MemberInfo this)
Parameters
System.Reflection.MemberInfo this

The member to use as the source.

Returns
MemberInfo<T>

A strongly-typed MemberInfo instance.

Type Parameters
T

The value type of the member.

Configured<T>(IConfigurationContainer)

Configures the container with a configuration profile. A configuration profile is a profile of configurations that can be applied to a configuration container. It is a way of preserving commonly-used configurations and applying them quickly to a configuration container.

Declaration
public static IConfigurationContainer Configured<T>(this IConfigurationContainer this)
    where T : class, IConfigurationProfile
Parameters
IConfigurationContainer this

The container to configure.

Returns
IConfigurationContainer

The configured container with the configuration profile applied to it.

Type Parameters
T

The type of the configuration profile.

ConfigureType<T>(IConfigurationContainer)

Declaration
[Obsolete("This will be removed in a future release.  Use IConfigurationContainer.Type<T> instead.")]
public static ITypeConfiguration<T> ConfigureType<T>(this IConfigurationContainer this)
Parameters
IConfigurationContainer this

Returns
ITypeConfiguration<T>

Type Parameters
T

Create(IContext)

The main event. Used to create a new serializer from the configured context (usually a IConfigurationContainer).

Declaration
public static IExtendedXmlSerializer Create(this IContext this)
Parameters
IContext this

The configured context that creates the serializer.

Returns
IExtendedXmlSerializer

The configured serializer.

EnableDeferredReferences(IConfigurationContainer)

This is an alternative version of enabling references on a configuration container and the subsequent serializers that it creates. It works much like EnableReferences(IConfigurationContainer), except that it will defer emitting the identity references until the last one is encountered. By contrast, EnableReferences(IConfigurationContainer) emits the identity references when it first encounters them, and then a reference back to the identity reference with each subsequent encounter.

Declaration
public static IConfigurationContainer EnableDeferredReferences(this IConfigurationContainer this)
Parameters
IConfigurationContainer this

The configuration container to configure.

Returns
IConfigurationContainer

The configured configuration container.

EnableReferences(IConfigurationContainer)

Enables references on a configuration container, which will create a serializer that supports circular references. When the first reference is encountered, it will be emitted. Further occurrences of the same reference will emit with a special attribute along with its unique value. This allows circular references to be serialized and subsequently deserialized appropriately and properly. Note that, by default, if this method is not invoked on a configuration container, and a serializer that it creates attempts to serialize an object with circular references, an exception is thrown.

Declaration
public static IConfigurationContainer EnableReferences(this IConfigurationContainer this)
Parameters
IConfigurationContainer this

The configuration container to configure.

Returns
IConfigurationContainer

The configured configuration container.

EnableReferences(IRootContext)

Declaration
[Obsolete("This is considered deprecated and will be removed in a future release.")]
public static IRootContext EnableReferences(this IRootContext this)
Parameters
IRootContext this

Returns
IRootContext

EnableReferences<T, TMember>(ITypeConfiguration<T>, Expression<Func<T, TMember>>)

Enables references on a configuration container, which will create a serializer that supports circular references. Additionally, this call will register a particular type as allowing references, and establish the member that evaluates with the provided expression as the identity member. Doing so will allow the serializer to keep track of references based on the unique values found with the identity member.

Declaration
public static ITypeConfiguration<T> EnableReferences<T, TMember>(this ITypeConfiguration<T> this, Expression<Func<T, TMember>> member)
Parameters
ITypeConfiguration<T> this

The type configuration under configuration.

System.Linq.Expressions.Expression<System.Func<T, TMember>> member

The member expression that is intended to resolve as the identity member for the type configuration.

Returns
ITypeConfiguration<T>

The configured type configuration.

Type Parameters
T

The type under configuration.

TMember

The resulting identity member value type.

Extend(IRootContext, ISerializerExtension[])

Used to extend a root context (usually a configuration container). This passes in a collection of extensions to add to the context's collection of serializer extensions.

Declaration
public static IRootContext Extend(this IRootContext this, params ISerializerExtension[] extensions)
Parameters
IRootContext this

The root context that contains the target collection of serializer extensions.

ISerializerExtension[] extensions

The array of extensions to add.

Returns
IRootContext

The configured context (usually a configuration container).

GetMember(ISource<MemberInfo>)

Convenience method for objects that implement several ISource<T> to get its member-based contents specifically.

Declaration
public static MemberInfo GetMember(this ISource<MemberInfo> this)
Parameters
ISource<System.Reflection.MemberInfo> this

The implementing source.

Returns
System.Reflection.MemberInfo

MemberInfo.

GetType(ISource<TypeInfo>)

Convenience method for objects that implement several ISource<T> to get its type-based contents specifically.

Declaration
public static TypeInfo GetType(this ISource<TypeInfo> this)
Parameters
ISource<System.Reflection.TypeInfo> this

The implementing source.

Returns
System.Reflection.TypeInfo

TypeInfo.

GetTypeConfiguration(IContext, TypeInfo)

Declaration
[Obsolete("This method is deprecated and will be removed in a future release.  Use IContext.GetTypeConfiguration(Type) instead.")]
public static ITypeConfiguration GetTypeConfiguration(this IContext this, TypeInfo type)
Parameters
IContext this

System.Reflection.TypeInfo type

Returns
ITypeConfiguration

GetTypeConfiguration(IContext, Type)

Gets or creates a type configuration from the container. Type configurations are configurations that deal specifically with a particular type and allow you to query its member configurations for further configuration of the type's members.

Declaration
public static ITypeConfiguration GetTypeConfiguration(this IContext this, Type type)
Parameters
IContext this

The context (usually a configuration containers) from which to request the type configuration.

System.Type type

The type to retrieve.

Returns
ITypeConfiguration

The type configuration.

Identity<T, TMember>(IMemberConfiguration<T, TMember>)

Flags the provided member configuration as the identity member for the container's references. Once an identity member is established, it is used to emit its unique value and to later read it during deserialization. The unique value is used to keep track of references in a different application and/or domain context from when the original serialization occurred.

Declaration
public static IMemberConfiguration<T, TMember> Identity<T, TMember>(this IMemberConfiguration<T, TMember> this)
Parameters
IMemberConfiguration<T, TMember> this

The member configuration to configure.

Returns
IMemberConfiguration<T, TMember>

The configured member configuration.

Type Parameters
T

The containing type of the member.

TMember

The member's value type.

IgnoredReferenceTypes(IConfigurationContainer)

Retrieves the current "blacklist" of ignored types on a configuration container. By default this is the see cref="String"/> type. If specified and populated, these are the only types that cannot have EnableReferences(IConfigurationContainer) called on them. Note that if both whitelist and blacklists are populated, the whitelist takes precedence.

Declaration
public static ICollection<TypeInfo> IgnoredReferenceTypes(this IConfigurationContainer this)
Parameters
IConfigurationContainer this

The configuration container to configure.

Returns
System.Collections.Generic.ICollection<System.Reflection.TypeInfo>

A collection of types that cannot be reference-enabled.

Member<T>(ITypeConfiguration<T>, MemberInfo)

Declaration
[Obsolete("This method has been replaced by MemberBy.")]
public static ITypeConfiguration<T> Member<T>(this ITypeConfiguration<T> this, MemberInfo member)
Parameters
ITypeConfiguration<T> this

System.Reflection.MemberInfo member

Returns
ITypeConfiguration<T>

Type Parameters
T

Member<T, TMember>(ITypeConfiguration<T>, Expression<Func<T, TMember>>)

Get (or create) the member configuration from the type that resolves with the provided expression.

Declaration
public static IMemberConfiguration<T, TMember> Member<T, TMember>(this ITypeConfiguration<T> this, Expression<Func<T, TMember>> member)
Parameters
ITypeConfiguration<T> this

The type configuration to configure.

System.Linq.Expressions.Expression<System.Func<T, TMember>> member

The expression to that resolves to a member of the type under configuration.

Returns
IMemberConfiguration<T, TMember>

The requested member configuration.

Type Parameters
T

The type under configuration.

TMember

The type of the member's value.

Member<T, TMember>(ITypeConfiguration<T>, Expression<Func<T, TMember>>, Action<IMemberConfiguration<T, TMember>>)

Get (or create) the member configuration from the type that resolves with the provided expression, and then configures it with the provided action.

Declaration
public static ITypeConfiguration<T> Member<T, TMember>(this ITypeConfiguration<T> this, Expression<Func<T, TMember>> member, Action<IMemberConfiguration<T, TMember>> configure)
Parameters
ITypeConfiguration<T> this

The type configuration to configure.

System.Linq.Expressions.Expression<System.Func<T, TMember>> member

The expression to that resolves to a member of the type under configuration.

System.Action<IMemberConfiguration<T, TMember>> configure

The configuration to perform on the member configuration once retrieved.

Returns
ITypeConfiguration<T>

The configured type configuration.

Type Parameters
T

The type under configuration.

TMember

The type of the member's value.

MemberBy<T>(ITypeConfiguration<T>, MemberInfo)

Get (or create) the member configuration from the type that resolves with the provided member metadata.

Declaration
public static IMemberConfiguration MemberBy<T>(this ITypeConfiguration<T> this, MemberInfo member)
Parameters
ITypeConfiguration<T> this

The type configuration to configure.

System.Reflection.MemberInfo member

The metadata used to query the type.

Returns
IMemberConfiguration

The located member configuration.

Type Parameters
T

The type under configuration.

MemberBy<T, TMember>(ITypeConfiguration<T>, MemberInfo<TMember>)

Get (or create) the member configuration from the type that resolves with the provided strongly-typed member metadata. Strongly-typed member metadata can be created via the use of the As<T>(MemberInfo) method.

Declaration
public static IMemberConfiguration<T, TMember> MemberBy<T, TMember>(this ITypeConfiguration<T> this, MemberInfo<TMember> member)
Parameters
ITypeConfiguration<T> this

The type configuration to configure.

MemberInfo<TMember> member

The strongly-typed metadata used to query the type.

Returns
IMemberConfiguration<T, TMember>

The located member configuration.

Type Parameters
T

The type under configuration.

TMember

The value type of the member.

Name<T>(ITypeConfiguration<T>, String)

Applies a name for the type. This provided name will be used to emit the type when needed during serialization, and again when needed during the reading of a deserialization.

Declaration
public static ITypeConfiguration<T> Name<T>(this ITypeConfiguration<T> this, string name)
Parameters
ITypeConfiguration<T> this

The type configuration to configure.

System.String name

The name to apply to the type.

Returns
ITypeConfiguration<T>

The configured type configuration.

Type Parameters
T

The type under configuration.

Name<T, TMember>(IMemberConfiguration<T, TMember>, String)

Applies a name for the member. This will result in emitting an element name for the member with the provided value during serialization, as well as reading the name from XML elements during deserialization.

Declaration
public static IMemberConfiguration<T, TMember> Name<T, TMember>(this IMemberConfiguration<T, TMember> this, string name)
Parameters
IMemberConfiguration<T, TMember> this

The member configuration to configure.

System.String name

The name to assign for the member under configuration.

Returns
IMemberConfiguration<T, TMember>

The configured member configuration.

Type Parameters
T

The containing type of the member.

TMember

The type of the member's value.

Order<T, TMember>(IMemberConfiguration<T, TMember>, Int32)

Sets the order for the given member. This is used in ordering all elements when they are emitted during serialization.

Declaration
public static IMemberConfiguration<T, TMember> Order<T, TMember>(this IMemberConfiguration<T, TMember> this, int order)
Parameters
IMemberConfiguration<T, TMember> this

The member configuration which to order.

System.Int32 order

The desired order value for the member.

Returns
IMemberConfiguration<T, TMember>

The configured member configuration.

Type Parameters
T

The containing type of the member.

TMember

The member's value type.

Type<T>(IConfigurationContainer)

Gets or creates a type configuration from the container. Type configurations are configurations that deal specifically with a particular type and allow you to query its member configurations for further configuration of the type's members.

Declaration
public static ITypeConfiguration<T> Type<T>(this IConfigurationContainer this)
Parameters
IConfigurationContainer this

The container from which to request the type configuration.

Returns
ITypeConfiguration<T>

The type configuration.

Type Parameters
T

The requested type.

Type<T>(IConfigurationContainer, Action<ITypeConfiguration<T>>)

Gets or creates a type configuration from the container, and then configures it with the provided action. Type configurations are configurations that deal specifically with a particular type and allow you to query its member configurations for further configuration of the type's members.

Declaration
public static IConfigurationContainer Type<T>(this IConfigurationContainer this, Action<ITypeConfiguration<T>> configure)
Parameters
IConfigurationContainer this

The container from which to request the type configuration.

System.Action<ITypeConfiguration<T>> configure

The configuration to perform on the type configuration once it has been retrieved.

Returns
IConfigurationContainer

The configured type configuration.

Type Parameters
T

The requested type.

With(IEnumerable<ISerializerExtension>, ISerializerExtension[])

Declaration
[Obsolete("This is considered deprecated and will be removed in a future release.  Use IRootContext.Extend instead.")]
public static ISerializerExtension[] With(this IEnumerable<ISerializerExtension> this, params ISerializerExtension[] extensions)
Parameters
System.Collections.Generic.IEnumerable<ISerializerExtension> this

ISerializerExtension[] extensions

Returns
ISerializerExtension[]

With<T>(IRootContext)

Finds or creates/add the requested serializer extension type. If an extension of the requested type already exists, it is returned. Otherwise, a new one is created by searching first for a singleton on the requested type, and creating a new instance by way of public constructor if not.

Declaration
public static T With<T>(this IRootContext this)
    where T : class, ISerializerExtension
Parameters
IRootContext this

The root context to search for a serializer extension of provided type.

Returns
T

The located or created serializer extension.

Type Parameters
T

The requested serializer extension type.

With<T>(IRootContext, Action<T>)

Finds or creates/add the requested serializer extension type, and then configures it with the provided action once it does.

Declaration
public static IRootContext With<T>(this IRootContext this, Action<T> configure)
    where T : class, ISerializerExtension
Parameters
IRootContext this

The root context to search for a serializer extension of provided type.

System.Action<T> configure

The configuration action to invoke once the serializer extension has been located.

Returns
IRootContext

The configured context (usually a configuration container).

Type Parameters
T

The requested serializer extension type.

Back to top Generated by DocFX